Question

Which of the following verifies that the user enters a positive integer value? O A int num=0; Scanner s = new Scanner(System.in); do t System.out.print Enter a positive integer: num s.nextlntO; } while (num 0) O B. int num=0; Scanner s = new Scanner(System.in); do t System.out.print Enter a positive integer: num = s.nextinto; } while (num % 2 != 0); int num=0; Scanner s = new Scanner(System.in do t System.out.print Enter a positive integer: num s.nextlntO; } while (num <= 0); O D. int num=0; Scanner s = new Scanner(System.in); do t System.out.print Enter a positive integer: num = s.nextlntO; łwhile (num 0):

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

From the below options The user enters a positive integer value

Answer is "D"


int num==0;

Scanner s=new Scanner(System.in);
do{
   System.out.print("Enter a positive integer:");
   num=s/nextint();
}while (num > 0);

Add a comment
Know the answer?
Add Answer to:
Which of the following verifies that the user enters a positive integer value? A. int num...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ANS (2) 0R hat output is produced by the following code if user enters these values...

    ANS (2) 0R hat output is produced by the following code if user enters these values for a question asked by the progran .User entered 3 Enter a positive integer value! (enter -1 to end) :3 Enter a positive integer value! (enter -1 to end) five Enter a positive integer value! (enter -1 to end) :7 Enter a positive integer value! (enter -1 to end) :-1 User entered five -User entered 7 ...User entered -1 import java.util.Scanner: class Verify input...

  • Please answer both questions thank you. Assuming that a user enters 8, 15, and 11 as...

    Please answer both questions thank you. Assuming that a user enters 8, 15, and 11 as input values one after another, separated by spaces, what is the output of the following code snippet? int num1 = 0; int num2 = 0; int num3 = 0; Scanner in = new Scanner (System.in); System.out.print("Enter a number: "); numl - in.nextInt(); System.out.print("Enter a number: "); num2 = in.nextInt(); System.out.print("Enter a number: "); num3 = in.nextInt(); if (numl > num2) if (numl > num3)...

  • Please help me with this Java project. I'm trying to create a loop so if user...

    Please help me with this Java project. I'm trying to create a loop so if user enter value > 12, will prompt them a message and take them back to "How many elements do you wan to enter?". Thanks public static void main(String[] args) {        Scanner sc = new Scanner(System.in);           int i, j;       System.out.print("\n How meny elements do you want to enter? (N should be no more than 12) ");    int num...

  • Question 15 After the following code executes, what is the output if user enters 0? int...

    Question 15 After the following code executes, what is the output if user enters 0? int x =-1; cout << "Enter O or 1:"; cin >> X; if (x) cout << true else cout << false O nothing will be displayed true O false 0

  • Please explain if the following code is actually correct. If the following code correct, please explain...

    Please explain if the following code is actually correct. If the following code correct, please explain why the code works and is also correct. Don’t use * Java’s Integer .toBinaryString(int) in this program./* According to the textbook and the instructor, I am not supposed to use arrays such as int binary[] = new int[25]; I guess this is the reason why this problem is starting to look kind of hard.   Chapter 5 Exercise 37: Java Programming * * (Decimal to...

  • Complete the do-while loop to output 0 to countLimit. Assume the user will only input a...

    Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }

  • What is the output of the following C++ code? int count = 1; int num =...

    What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...

  • I need help asking the user to half the value of the displayed random number as...

    I need help asking the user to half the value of the displayed random number as well as storing each number generated by the program into another array list and displayed after the game is over at the end java.util.*; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in);    ArrayList<Integer> data = new ArrayList<Integer>(); int count = 0; while (!choice.equals("No")) { int randomInt =...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

  • In Java JOptionPane how do you validate if a user enters an integer value? How do...

    In Java JOptionPane how do you validate if a user enters an integer value? How do you reprompt the user to enter an integer if they first entered a double or a string value? int length = Integer.parseInt(JOptionPane.showInputDialog("Enter the length: ")); int width = Integer.parseInt(JOptionPane.showInputDialog("Enter the width: ")); int height = Integer.parseInt(JOptionPane.showInputDialog("Enter the height: "));

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT