I am new to programming and Java. I am trying to make 3 methods. One gets the largest number, one gets the middle, and the last gets the smallest. I do not think I created them correctly. I am getting a compiler error in Jgrasp saying illegal start to expression for
each method. Then how do I call them? Here is my code:
thanks in advanceimport java.util.*; public class Ch4_PrExercise2 { public static void main(String [] args) { Scanner console = new Scanner(System.in); int num1, num2, num3; System.out.println("Please input 3 numbers separated by spaces: "); System.out.println(); num1 = console.nextInt(); num2 = console.nextInt(); num3 = console.nextInt(); public int largest() { if(num1 > num2 && num1 > num3) return num1; else if(num2 > num1 && num2 > num3) return num2; else if(num3 > num1 && num3 > num2) return num3; } public int smallest() { if(num1 < num2 && num1 < num3) return num1; else if(num2 < num1 && num2 < num3) return num2; else if(num3 < num1 && num3 < num2) return num3; } public int middle() { if((num1 < num2 && num1 >num3) || (num1 > num2 && num1 < num3)) return num1; else if((num2 > num1 && num2 < num3) || (num2 < num1 && num2 >num3)) return num2; else if((num3 > num2 && num3 < num1) || (num3 < num2 && num3 > num1)) return num3; } System.out.println("Your numbers in nondescending order are: " + " " + smallest() + " " + middle() + " " largest()); } }