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
maxonik [38]
3 years ago
13

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

consisting of integers only. The method reads all the integers remaining to be read in standard input and returns the number that are positive. So if the input were: 19 -5 -3 -251 14 -7 -14 6 the method would return 3 because there are 3 positive integers there. The method must not use a loop of any kind (for, while, do-while) to accomplish its job.

Computers and Technology
1 answer:
NNADVOKAT [17]3 years ago
3 0

Answer:

Here is the method countPos    

  static int countPos(Scanner input){ //method that takes a reference to a Scanner object

   int counter=0;  // to count the positive integers  

   int number; //to store each integer value

   if(input.hasNextInt()){ //checks if next token in this scanner input is an integer value

       number=input.nextInt(); //nextInt() method of a Scanner object reads in a string of digits and converts them into an int type and stores it into number variable

       counter=countPos(input); //calls method by passing the Scanner object and stores it in counter variable

       if(number>0) //if the value is a positive number

           counter++;    } //adds 1 to the counter variable each time a positive input value is enountered

   else    { //if value is not a positive integer

       return counter;    } //returns the value of counter

   return counter; } //returns the total count of the positive numbers

Explanation:

Here is the complete program:

import java.util.Scanner; //to take input from user

public class Main { //class name

//comments with each line of method below are given in Answer section

static int countPos(Scanner input){

   int counter=0;

   int number;

   if(input.hasNextInt()){

       number=input.nextInt();

       counter=countPos(input);

       if(number>0)

           counter++;    }

   else    {

       return counter;    }

   return counter; }

public static void main(String[] args) { //start of main function

       System.out.println("Number of positive integers: " + countPos(new Scanner(System.in)));  } } //prints the number of positive integers by calling countPos method and passing Scanner object to it

The program uses hasNextInt method that returns the next token (next input value) and if condition checks using this method if the input value is an integer. nextInt() keeps scanning the next token of the input as an integer. If the input number is a positive number then the counter variable is incremented to 1 otherwise not. If the use enters anything other than an integer value then the program stops and returns the total number of positive integers input by the user. This technique is used in order to avoid using any loop. The program and its output is attached

You might be interested in
Which of these can a worksheet within a spreadsheet contain?
Lisa [10]
<span>d) all of these is your correct answer</span>
3 0
3 years ago
Read 2 more answers
Consider an error-free 64 kbps satellite channel used to send 512 byte data frames in one direction, with very short acknowledge
Vladimir [108]

Answer:

The answer is "2".

Explanation:

In the given question some information is missing, that is "The propagation time for satellite to earth" which is "270 milliseconds" so, the description to this question can be defined as follows:

Given values:

Bandwidth = 64 kbps

Data frames = 512 bytes  

Propagation Time (t​​​​​​p ) =270 ms

Change Bandwidth  kbps to bps:

1 kb= 1024 bytes

calculated bandwidth= 64 kbps = 64×1024 bps = 65536 bps

1 bytes = 8 bits

512 bytes = 512 × 8 =  4096 bits

Frame length = 4096 bits

Formula

Transmission time (T​​​​​​t) = Frame length /Bandwidth

Window size = 1+2a

where a = Propagation time/Transmission time

Calculate Transmission time:

Transmission time (T​​​​​​t) = 4096 / 65536

Transmission time (T​​​​​​t)= 625 m.sec

Calculate Window size:

Window size = 1+2(270/625)

Window size = 1+2(0.432)

Window size = 1+0.864

Window size = 1.864

Window size = 2

3 0
3 years ago
In which state of matter is there no particle motion?
kiruha [24]
Solid is your answer for the day
6 0
3 years ago
Jeff gave a presentation that attempted to convince stockholders to purchase the new software he had developed. What type of pre
Travka [436]

Answer: Progress report presentation

Explanation: Progress report presentation is the presentation that consist the progress report of an individual's work .It describes about the project/work that a person has started to complete the project. These reports are made for the clients, students, colleagues etc.

Progress report in this case is made for the client to make them understand about the Jeff's work , his contribution, changes he invoked in it, achievements ,completion of the project, benefits of it etc. This presentation will encourage the client to buy the software made by Jeff.

7 0
3 years ago
URGENT!!! Which file format is used mainly in the Microsoft Windows operating system?
zzz [600]

Answer:

C.   BMP

Explanation:

BMP is a simple bitmap image format developed by Microsoft and IBM.

It's used almost exclusively on the Microsoft Windows operating system these days, was used on OS/2.  It's the format the basic MS Paint program, that comes with Windows, edits its file in.

It's also a basic graphic format to use for programmers.

Of course GIF, PDF, TIFF and PNG are also used on Windows, as well as on most other operating system.

6 0
3 years ago
Other questions:
  • Digital art is created by using
    6·1 answer
  • What can you do to stop a computer from repeatedly restarting in a continuous loop?
    13·1 answer
  • Mateo could not find the undo command or shortcut. He should _____.
    15·2 answers
  • NIST recommends selecting cloud providers that support strong encryption, have appropriate redundancy mechanisms in place, emplo
    11·1 answer
  • To create a new query in Design view, click CREATE on the ribbon to display the CREATE tab and then click the ____ button to cre
    9·1 answer
  • Paula weeded 40% of her garden in 8 minutes. How many minutes will it take to weed all of her garden at this rate ?
    7·1 answer
  • Learning Management Systems (LMS) allow students to interact with each other, but NOT their teachers.
    10·2 answers
  • Robyn needs to ensure that a command she frequently uses is added to the Quick Access toolbar. This command is not found in the
    11·1 answer
  • Write the use of the Goto statement with the help of an example.
    9·1 answer
  • How do the following technologies help you with your quest to become a digital citizen kiosks enterprise computing, natural lang
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!