Question

In: Computer Science

JAVA programming language: For refrence: nextInt ( ) Scans the next token of the input as...

JAVA programming language:

For refrence:

nextInt ( )

Scans the next token of the input as an int.

How many times does the while loop execute, if the input is 38 20 4 0?

Assume a Scanner object scnr has been instantiated, and that the tokens in the input are delimited by the space character. That means there are 4 tokens in the input.

int num = 2000;

while (num >= 20) {

//Do something

num = scnr.nextInt();

}

select one:

a. 2

b. 1

c.0

d.3

Solutions

Expert Solution

SOLUTION-

Correct answer is "(d) 3 "

Loop starts with 2000,

In the loop next assigned value for number is 38, from the given input and 38>=20 (meets condition)

In next iteration 20 will be assigned to num and that value also satisfies the condition.20>=20

In next iteration num will be 4 which breaks the loop condition because (4 >=20 is false) and breaks, so the loop repeats 3 times before exiting.

You can refer to the code below .


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

JAVA PROGRAMMING LANGUAGE Suppose a library is processing an input file containing the titles of books...
JAVA PROGRAMMING LANGUAGE Suppose a library is processing an input file containing the titles of books in order to identify duplicates. Write a program that reads all of the titles from an input file called bookTitles.inp and writes them to an output file called duplicateTitles.out. When complete, the output file should contain all titles that are duplicated in the input file. Note that the duplicate titles should be written once, even though the input file may contain same titles multiple...
in the c programming language input is given in the form The input will be of...
in the c programming language input is given in the form The input will be of the form [number of terms] [coefficient k] [exponent k] … [coefficient 1] [exponent 1] eg. 5 ─3 7 824 5 ─7 3 1 2 9 0 in this there are 5 terms with -3x^7 being the highest /* Initialize all coefficients and exponents of the polynomial to zero. */ void init_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Java Programming In this assignment we are going to create our own programming language, and process...
Java Programming In this assignment we are going to create our own programming language, and process it Java. programming language has 6 commands enter add subtract multiply divide return enter, add, subtract, multiply, divide all take 1 parameter (a double value). return takes no parameters.
Java programming language Write a Java application that simulates a test. The test contains at least...
Java programming language Write a Java application that simulates a test. The test contains at least five questions. Each question should be a multiple-choice question with 4 options. Design a QuestionBank class. Use programmer-defined methods to implement your solution. For example: - create a method to simulate the questions – simulateQuestion - create a method to check the answer – checkAnswer - create a method to display a random message for the user – generateMessage - create a method to...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
Programming language is Java: Write a pseudocode method to determine if a set of parentheses and...
Programming language is Java: Write a pseudocode method to determine if a set of parentheses and brackets is balanced. For example, such a method should return true for the string, "[()]{}{[()()]()}" and false for the string "[(])". Also please discuss how the algorithm will perform and how much space in memory it will take if somebody passes a massive string as input.
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the...
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the user. Write a program with conditional statements. Write a program with loops. Specifications Think of three countries you’d like to travel to and look up the conversion rate between dollars and the money used in those countries. (See http://www.ratesfx.com/ rates/rate-converter.html for conversion rates.) Write a program that will convert money from dollars into each of those three types of currency, or from one of...
In the programming language java: Write a class encapsulating the concept of a telephone number, assuming...
In the programming language java: Write a class encapsulating the concept of a telephone number, assuming a telephone number has only a single attribute: aString representing the telephone number. Include a constructor, the accessor and mutator, and methods 'toString' and 'equals'. Also include methods returning the AREA CODE (the first three digits/characters of the phone number; if there are fewer than three characters in the phone number of if the first three characters are not digits, then this method should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT