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
oee [108]
4 years ago
13

Write the definition of a method named add that receives a reference to a Scanner object associated with a stream of input consi

sting of integers only. The method reads all the integers remaining to be read from the stream and returns their sum. So if the input were 3 51 204 17 1040 the returned value would be 1315
The method must not use a loop of any kind (for, while, do-while) to accomplish its job.
Computers and Technology
1 answer:
Lisa [10]4 years ago
5 0

Answer:

import java.util.*;

class Main  

{

   public static void main(String[] args)

   {

       System.out.println("Enter integers and 0 to exit");

       Scanner a1=new Scanner(System.in);

       System.out.println(add(a1));

       

   }

  public static int add(Scanner a1)

  {

        int total = a1.nextInt();

          if (a1.hasNextInt())

              {

                 total =total +add(a1);

              }

       return total;

   }

}

Explanation:

The only thing that needs explanation here is hasnextInt. This returns true if entered number is integer and false if entered is not an integer. And rest is as shown in the program.

You might be interested in
What can the tab key do
bulgar [2K]
Answer: it indents

Explanation:
8 0
3 years ago
To rename a worksheet, you change the text on the ? HELP ASAP
prohojiy [21]
If this is Excel, it would be C. Sheet tab
5 0
3 years ago
I can’t get answers because the ads won’t load help me
Flura [38]

Answer: Get better wifi

Explanation: This maybe a router problem, Go to your router and reset it by unplugging the power chord, After 30 seconds plug it back in and wait for your wifi to start back up. Your ads should load now. Have a good day.

7 0
3 years ago
Consider the following class definitions.public class Bike{private int numWheels = 2;// No constructor defined}public class EBik
nadya68 [22]

Answer:

The answer is "Option A".

Explanation:

Please find the complete program in the attached file.

The given program includes a super-class Bike having a private integer numWheels parameter. The class EBike inherits the class Bike, EBike comprises one parameter function Object() which utilizes its variable number of the private integer Battery level of the battery parameter and the wrong choice can be defined as follows:

In choice B, it is wrong since there is no constructor with a single argument in the Bike class.

In choice C, it is wrong since there no need to call the base class constructor with the super keyword.

In choice, D is wrong because there no need to create a constructor of the base class.

In choice, E is wrong because it does not require the second EBike constructor parameter.

4 0
3 years ago
Which online resource is usually not free?
Andrej [43]

Answer:

educational tutoring

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Type the correct answer in the box spell all words correctly
    8·1 answer
  • GenXTech is a growing company that develops gaming applications for military simulations and commercial clients. As part of its
    8·1 answer
  • Abigail is writing an email to Justine Swenson, a friend of her best friend, Jane, inviting her to a get-together.
    7·1 answer
  • Which phrase refers to the collection of geospatial data through the use of satellite images/pictures?
    13·1 answer
  • The purpose of maintaining a network of digital forensics specialists is to develop a list of colleagues who specialize in areas
    7·2 answers
  • To which of these options does the style in Word apply? Select three options.
    7·1 answer
  • Hey guys!
    5·2 answers
  • Directions and Analysis
    15·1 answer
  • What should you consider when using a wireless keyboard with your home computer
    15·1 answer
  • Which of the following correctly calculates the
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!