// DebugFive4.java // Outputs highest of four numbers import java.util.*; public
ID: 3747375 • Letter: #
Question
// DebugFive4.java
// Outputs highest of four numbers
import java.util.*;
public class DebugFive4
{
public static void main (String args[])
{
Scanner input = new Scanner(System.in);
int one, two, three, four;
String str, output;
System.out.println("Enter an integer");
str = input.next();
> System.out.println("Enter an integer");
str = input.next();
two = Integer.parseInt(str);
System.out.println("Enter an integer");
str = input.next();
three = Integer.parseInt(str);
System.out.println("Enter an integer");
str = input.next();
four = Integer.parseInt(str);
if(one > two > one > three > one > four)
output = "Highest is " + four;
else
if(two > one && two > three !! two > four)
output = "Highest is " + three;
else
if(three > one && three > two && three > four)
output = "Highest is " + three;
else
output = "Highest is " + four;
System.out.println(output);
}
}
Explanation / Answer
import java.util.*;
public class DebugFive4{
public static void main(String []args){
Scanner input = new Scanner(System.in);
int one, two, three, four;
String str, output;
System.out.println("Enter an integer");
str = input.next();
> System.out.println("Enter an integer");
str = input.next();
two = Integer.parseInt(str);
System.out.println("Enter an integer");
str = input.next();
three = Integer.parseInt(str);
System.out.println("Enter an integer");
str = input.next();
four = Integer.parseInt(str);
if(one >= two && one >= three && one >= four ) /* conditions for first number is Highest */
output = "Highest is " + one;
else
if(two >= one && two >= three && two >= four) /* conditions for second number is Highest */
output = "Highest is " + two;
else
if(three >= one && three >= two && three >= four) /* conditions for third number is Highest */
output = "Highest is " + three;
else
output = "Highest is " + four; /* If all are less then last number is Highest */
System.out.println(output);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.