1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Zielflug [23.3K]
3 years ago
12

Write a complete Java method that returns an integer. The method declares a Scanner object, then prompts the user for a series o

f integers in a while loop. If the user enters an integer (not a string, double, etc) then read each value entered and keep a running total (a sum). Make sure to validate that the user enters only integers. Include a sentinel value (-1) to allow the user to indicate when they are done. The method returns the total.
Computers and Technology
1 answer:
igor_vitrenko [27]3 years ago
3 0

Answer:

Here is code in java.

import java.util.*;

class Main

{

 // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

        // print the running total of all inputs

       System.out.println("total of all the inputs is: "+fun());

       

   }catch(Exception ex){

       return;}

}

/* function to take input from user until input is -1

 and keep a running total */

public static int fun()

{

    int in;

     //scanner class object to read the input

    Scanner scr=new Scanner(System.in);

     // variable to keep running total

    int total=0;

    System.out.println("please enter an Integer:(-1 to stop)");

     // read the input first time

    in=scr.nextInt();

    while(in!=-1)

    {

     // this loop keep taking input until input is -1.

     // calculate running total of all inputs

        total=total+in;

        System.out.println("please enter an number:(-1 to stop)::");

        in=scr.nextInt();

       

    }

     // return total of all inputs

    return total;

   

}

}

Explanation:

Create an object of scanner class in the method fun_tot(),it will take input from user.In while loop it will ask user to give input and calculate the sum of all inputs.when user enter -1 then while loop breaks and the method will return the total of all inputs given by the user.

Output:

please enter an number:(-1 to stop)::23

please enter an number:(-1 to stop)::3

please enter an number:(-1 to stop)::5

please enter an number:(-1 to stop)::76

please enter an number:(-1 to stop)::12

please enter an number:(-1 to stop)::-1

total of all the inputs is: 119

You might be interested in
____ is (are) the abuse of e-mail systems to send unsolicited e-mail to large numbers of people.
Volgvan
Pretty sure answer is <span>E-mail spam</span>
4 0
3 years ago
Is this good connection to be able to record edit and post videos?
Sholpan [36]

Answer:

The answer to your query is Yes and the details are in explanation section.

Explanation:

The general rule video is

  • if you have 3 MB speed is enough for normal video.
  • 5 MB for HD
  • 25 MB for HDR or 4K

For the above it is clear that yes your connection is good enough for videos.

but it lack in HDR or 4K  videos.

4 0
3 years ago
How does Python recognize a tuple?
Talja [164]

Answer:

B) You use parentheses around the data values

Explanation:

It was C) on my end, but the answer is still the same :)

7 0
3 years ago
Read 2 more answers
After a programmer plans the logic of a program, the next step is to __________
Snezhnost [94]

Following the <u>planning of a program's logic by a programmer</u>, the program is coded. <u>Programming enables users to create computer code, apps, and websites</u>. Programming is defined as the <u>process of writing instructions</u> for computers using computer languages.

  • Computer code is used to code the websites, apps, and other technologies with which we interact daily.
  • Many of the finest tech jobs necessitate the ability to code.

Therefore, the final answer is "Coding the Program ".

Learn more:

brainly.com/question/735555

5 0
3 years ago
Which of the following tasks is an interactive media professional most likely to do? Check all of the boxes that apply. 1. decid
GREYUIT [131]

Answer:

decide how a website should look and  

test a software program to ensure that the visual elements are working

Explanation:

i just did it

8 0
3 years ago
Other questions:
  • Describe what a layer 3 router is and what are its advantages and drawbacks compared to other network devices.
    15·1 answer
  • Which method deletes a footer from a document?
    9·2 answers
  • You can upgrade a cpu by adding registers and cache memory to it. <br> a. True <br> b. False
    7·1 answer
  • What is the meaning of the word joystick
    6·2 answers
  • A network with 6 bits remaining for the host portion will have how many usable hosts?​
    9·1 answer
  • Finding information on the Web is easy thanks to _____________, which provide on-screen menus, making navigation of the web as s
    11·1 answer
  • Write a recursive function that returns 1 if an array of size n is in sorted order and 0 otherwise. Note: If array a stores 3, 6
    6·1 answer
  • What's the difference between natural systems and man made systems <br>​
    8·1 answer
  • Which activity is performed during high-level design in the V-model?
    9·1 answer
  • When should students in a study session use flash cards to quiz one another?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!