Question: Read two positive inputs, the first less than the second. 6 0 0 8 4 6 . 4 0 3 9 4 6 0 .

Read two positive inputs, the first less than the second.
600846.4039460.qx3zqy7
Complete this program, prompting the user to enter two positive numbers a and b so that a is less than b.
import java.util.Scanner;
public class TwoNumbers
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int a;
int b;
do {
System.out.println("Enter two positive integers, the first smaller than the second.");
System.out.print("First: ");
a = in.nextInt();
System.out.print("Second: ");
b = in.nextInt();
if (a >= b || a <=0|| b <=0){
System.out.println("Invalid input. Please try again.");
}
} while (a >= b || a <=0|| b <=0);
// This line should only be printed when the input is correct
System.out.println("You entered "+ a +" and "+ b);
}
}
Not all tests passed.
1: Compare output
Output differs. See highlights below.
Special character legend
Input
7337
Your output
Enter two positive integers, the first smaller than the second.
First: Second: Invalid input. Please try again.
Enter two positive integers, the first smaller than the second.
First: Second: You entered 3 and 7
Expected output
Enter two positive integers, the first smaller than the second.
First: 7
Second: 3
Enter two positive integers, the first smaller than the second.
First: 3
Second: 7
You entered 3 and 7
Output a newline using System.out.println().
You are missing a newline here.
You are missing a newline here.
2: Compare output
Output differs. See highlights below.
Special character legend
Input
730337
Your output
Enter two positive integers, the first smaller than the second.
First: Second: Invalid input. Please try again.
Enter two positive integers, the first smaller than the second.
First: Second: Invalid input. Please try again.
Enter two positive integers, the first smaller than the second.
First: Second: You entered 3 and 7
Expected output
Enter two positive integers, the first smaller than the second.
First: 7
Second: 3
Enter two positive integers, the first smaller than the second.
First: 0
Second: 3
Enter two positive integers, the first smaller than the second.
First: 3
Second: 7
You entered 3 and 7
Output a newline using System.out.println().
You are missing a newline here.
You are missing a newline here.
You are missing a newline here.
3: Compare output
Output differs. See highlights below.
Special character legend
Input
42-4-224
Your output
Enter two positive integers, the first smaller than the second.
First: Second: Invalid input. Please try again.
Enter two positive integers, the first smaller than the second.
First: Second: Invalid input. Please try again.
Enter two positive integers, the first smaller than the second.
First: Second: You entered 2 and 4
Expected output
Enter two positive integers, the first smaller than the second.
First: 4
Second: 2
Enter two positive integers, the first smaller than the second.
First: -4
Second: -2
Enter two positive integers, the first smaller than the second.
First: 2
Second: 4
You entered 2 and 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!