
Isiah K.
asked 10/24/20I need help debugging this code, I have tried multiple times and still am having trouble please help.
My assignment is to debug this code, however I am not sure about what I am doing wrong.
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();
one = Integer.parseInt(str);
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);
}
}
2 Answers By Expert Tutors
Mort M. answered 10/28/20
E.E./Computer Science graduate 10+ years Java tutoring experience
package sandbox;
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();
one = Integer.parseInt(str);
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 " + one;
}
else
if(two > one && two > three && two > four)
{
output = "Highest is " + two;
}
else
if(three > one && three > two && three > four)
{
output = "Highest is " + three;
}
else
{
output = "Highest is " + four;
}
System.out.println(output);
input.close();
}
}

Patrick B. answered 10/24/20
Math and computer tutor/teacher
import java.io.*;
class SortMax
{
private int A[];
SortMax()
{
A = new int[4];
for (int iLoop=0; iLoop<4; iLoop++)
{
A[iLoop]=0;
}
}
public void Input()
{
Console console = System.console();
for (int iLoop=0; iLoop<4; iLoop++)
{
System.out.print(" Please input # " + (iLoop+1) + " :>");
String inbuff = console.readLine();
A[iLoop] = Integer.parseInt(inbuff);
}
}
public void Sort ()
{
for (int iLoop=3; iLoop>=0; iLoop--)
{
for (int jLoop=0; jLoop<iLoop; jLoop++)
{
if (A[jLoop] > A[jLoop+1])
{
int iTemp = A[jLoop+1];
A[jLoop+1] = A[jLoop];
A[jLoop] = iTemp;
} //swap
} //for jLoop
} //for iLoop
}
public void Go()
{
this.Input();
this.Sort();
System.out.println(" the max is " + A[3]);
System.out.println(" the min is " + A[0]);
System.out.println(" sorted list increasing :");
for (int iLoop=0; iLoop<4; iLoop++)
{
System.out.println(A[iLoop]);
}
System.out.println("---------------------------------");
System.out.println(" sorted list decreasing :");
for (int iLoop=3; iLoop>=0; iLoop--)
{
System.out.println(A[iLoop]);
}
}
public static void main(String args[])
{
SortMax x = new SortMax();
x.Go();
}
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code posted under this link... Bubble sorts the 4 integers10/24/20