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
11. Explain different types of program control with suitable flow chart.<br> N
melamori03 [73]

hi

Counting a sequence of statements without any decisions or branches as one control structure (as many computer scientists do),the if, if-else, and if-else-if ladders as one control structure,the three types of loops (while, do-while, and for) as three different control structures,the break and continue statements, in the context of loops, as one more (although this can be debatable),the switch/case control structure as one,the call/return mechanism as one,the ability to specify and call a callback function as one,the goto/label as one,and the setjmp/longjmp non-local goto as one,

5 0
2 years ago
Machine-to-machine (M2M) technology enables sensor-embedded products to share reliable real-time data ________.Select one:a. ove
just olya [345]

Answer:b)via radio signals

Explanation: Machine-to-machine technology is the technology that helps in sharing of the real time information of the device that have embedded sensor.They can work without the help of the manual factors.

The data is shared through the help of the radio signals in the devices like turbines vending machines etc for the tracking purpose and managing.

Thus the other options are incorrect because short distance is a disttance, cloud services are for the collection of services and databases contains the data. So, the correct option is option (b).

5 0
3 years ago
Create an java application that will process 3-digit numbers as follows:
alisha [4.7K]

Answer:

I dont not not the frsidjkbzxc.n bzl,b vbsv,gcjdvc,

Explanation:

5 0
3 years ago
Select all that apply.
rosijanka [135]

Answer:

don't overuse special effects, match special effects to content, use consistent transitions for each slide

Explanation:

I found this on quizlet.

6 0
2 years ago
An online retailer is looking to implement an enterprise platform. Which component of the enterprise platform will help the comp
adelina 88 [10]

Answer: Data and Insights

Explanation:

Data and Insights in an enterprise platform is very important as it helps users better understand their customers so that they may be able to offer them the best services.

Data allows the platform to capture the data of the customer and insights then curates and consumes the data for analysis. The result of this analysis will enable the company to better understand the customer so that they might be able to offer preferable products.

3 0
2 years ago
Other questions:
  • Which of the following filenames is acceptable on both Windows and Mac<br> operating systems?
    9·1 answer
  • The fast food restaurant Chipotle pulled its app from Apple's app store when customer demand caused the firm's servers to crash.
    14·1 answer
  • What are the first and the last physical memory addressesaccessible using
    10·1 answer
  • Python program: Develop a program that will keep track of inventory for a local retail store. Fortunately, the store only offers
    7·2 answers
  • How do you make your graphics ADA accessible in BlueGriffon?
    12·2 answers
  • Chapter 15 Problem 6 PREVENTIVE CONTROLS Listed here are five scenarios. For each scenario, discuss the possible damages that ca
    11·1 answer
  • Write a method printshampoolnstructions0, with int parameter numCycles, and void return type. If numCycles is less than 1, print
    8·1 answer
  • Define the function max2 that takes two integers as arguments and returns the largest of them. Then define the function max_list t
    11·1 answer
  • Yall like portal 1 or 2
    8·1 answer
  • Draw
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!