Using jGrasp write a program that prompts the user to input three numbers. This
ID: 3695972 • Letter: U
Question
Using jGrasp write a program that prompts the user to input three numbers. This program should then output the numbers in nondescending order. I am getting three errors so far starting at line 14 as it cannot find symbol for num1 = scn.nextint(); I am including a screenshot of errors followed by the entire syntax of the program. Please help make program work.
Here is my program
import java.util.Scanner;
public class NumbersNonDescending
{
//main method
public static void main(String [] args)
{
int num1, num2, num3;
Scanner scn = new Scanner(System.in);
System.out.print("Enter any three numbers:");
num1 = scn.nextlnt();
num2 = scn.nextlnt();
num3 = scn.nextlnt();
System.out.print(" Given the input the order is:"+num1+ " "+num2+" "+num3+" ");
if(num2 < num2)
{
if (num2 < num3)
System.out.println("The nondescending order of input is: " + num1 + " " + num2 + " " + num3);
else
System.out.println("The nondescending order of input is: " + num1 + " " + num3 + " " + num2);
} else if (num2 < num1)
{
if (num1 < num3)
System.out.println("The nondescending order of input is: " + num2 + " " + num1 + " " + num3);
else
System.out.println("The nondescending order of input is: " + num2 + " " + num3 + " " + num1);
}
else if (num3 < num1){
if (num2 < num1)
System.out.println("The nondescending order of input is: " + num3 + " " + num1 + " " + num2);
else
System.out.println("The nondescending order of input is: " +num3 + " " + num2 + " " + num1);
}
}
}
Explanation / Answer
NumbersNonDescending.java
import java.util.Scanner;//scanner class for keyboard inputting
public class NumbersNonDescending {
//main method
public static void main(String[] args) {
int num1, num2, num3;
Scanner scn = new Scanner(System.in);
System.out.print("Enter any three numbers:");
num1 = scn.nextInt();//keyboard inputting of numbers
num2 = scn.nextInt();
num3 = scn.nextInt();
System.out.print(" Given the input the order is:" + num1 + " " + num2 + " " + num3 + " ");
System.out.print("Numbers in NonDescending order:");
if ((num1 > num2 && num1 > num3))
{//if statements for nondescending order
if(num2 > num3)
{
System.out.print(num3 + " " + num2 + " " + num1);
}
else
System.out.print(num3 + " " + num2 + " " + num1);
}
else if ((num2 > num1 && num2 > num3))
{
if(num1 > num3)
{
System.out.print(num1 + " " + num3 + " " + num2);
}
else
{
System.out.print(num1 + " " + num3 + " " + num2);
}
}
else if ((num3 > num1 && num3 > num2))
{
if(num1 > num2)
{
System.out.print(num2 + " " + num1 + " " + num3);
}
else
System.out.print(num2 + " " + num1 + " " + num3);
}
}
}
output
Enter any three numbers:45 2 1
Given the input the order is:45 2 1
Numbers in NonDescending order:1 2 45
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.