answer.
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]
2 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]2 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
True or false words spelling and grammar check is always %100
OverLord2011 [107]
I don't quite understand what you are asking but if you are asking if word, spelling and grammar checkers are always 100% accurate then that is false :) 
6 0
2 years ago
Read 2 more answers
Assign courseStudent's name with Smith, age with 20, and ID with 9999. Use the printAll() member method and a separate println()
vekshin1

Answer:

Following are the program in the java language  

public class Main // Main class  

{

   String courseStudentsname; // variable declaration  

   int age; // variable declaration  

   int ID; // variable declaration  

   Main() // default constructor

   {

courseStudentsname="Smith";//assign the values mention in the question              

       age=20;//assign the values which is mention in the question  

       ID=9999;//assign the values which is mention in the question    

   }

void printAll() // method definition of printAll()  

   {

      System.out.print("Name: " + courseStudentsname ); // display name

      System.out.print(", Age: " + age); // display age

      System.out.print(", ID: " + ID); // display id

   }

public static void main(String[] args) // main fuunction()

{

Main ob=new Main(); // create the object of Main class  

ob.printAll(); // calling the method printAll()

}

}

Output:

Name:"Smith, Age:20, ID:9999

Explanation:

Following are the description of program

  • Create a constructor of "Main" class and store the respective values of courseStudentsname,age and ID in that constructor .
  • create a method printAll() and print the respective values in the given format which is mention in the question by using   System.out.print method.
  • In the main function create an object of "Main" class i.e "ob".
  • Finally, call the printAll() method by using the object of Main class.

4 0
2 years ago
ACCOUNTING
ivann1987 [24]

last question is D

Hope this helps

7 0
2 years ago
Read 2 more answers
12) Suppose you wanted a subroutine to return to an address that was 3 bytes higher in memory than the return address currently
Snezhnost [94]

Answer:

.code

main proc

mov ecx,ebp

mov ecx, 787878

push ecx

call MySe7en

invoke ExitProcess,0

main endp

MySe7en PROC

pop ecx

sub ecx, 3

mov

push ecx

ret

end main

8 0
2 years ago
Into which of these files would you paste copied information to create an integrated document?
Oksanka [162]
D cause you will need to keep up with data also
7 0
2 years ago
Read 2 more answers
Other questions:
  • The term load is often used to describe opening a page in a ____. Answer
    11·1 answer
  • Which type of address is used at the transport layer to identify the receiving application?
    14·1 answer
  • Programming challenge description: Write a program that, given two binary numbers represented as strings, prints their sum in bi
    6·1 answer
  • A Class B network needs to be subnetted such that it supports 100 subnets and 100 hosts/ subnet. Which of the following answers
    8·1 answer
  • Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message
    14·1 answer
  • Write a while loop that prints usernum divided by 2 until user_num is less than 1. The value of user_num changes inside of the l
    14·1 answer
  • In this assignment, you are provided with working code that does the following: 1. You input a sentence (containing no more than
    14·1 answer
  • An extranet is like an intranet except that it allows company employees access to corporate Web sites from the ______
    13·1 answer
  • Write a program that reads the lengths of the sides of a triangle from the user. Compute the area of the triangle using Heron's
    8·1 answer
  • 1. (1 point) Which flag is set when the result of an unsigned arithmetic operation is too large to fit into the destination? 2.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!