Problem: 9.20 LAB: Max and min numbers Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is:...




Problem:




9.20 LAB: Max and min numbers





Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values.


Ex: If the input is:


7 15 3

the output is:


largest: 15 smallest: 3

Your program must define and call the following two methods. The method largestNumber() should return the largest number of the three input values. The method smallestNumber() should return the smallest number of the three input values.
public static int largestNumber(int num1, int num2, int num3)
public static int smallestNumber(int num1, int num2, int num3)





Java code:



import java.util.Scanner;


public class LabProgram {


/* Define your method here */public static int largestNumber(int num1, int num2, int num3) {
int largest;


if ((num1 > num2) && (num1> num3)) {
largest=num1;
} else if (num2 > num3 && num2 > num1)

largest=num2;
} else {
largest=num3;
}
return largest;
}


public static int smallestNumber(int num1, int num2, int num3
int smallest;



if ((num1 < num2)="" &&="">< num3))="">
smallest=num1;
} else if (num2 < num3="" &&="" num2=""><>

smallest=num1;
} else {
smallest=num1;
}
return smallest;
}


public static void main(String[] args) {
/* Type your code here. */Scanner scnr = new Scanner(System.in);
user1=scnr.nextInt();
user2=scnr.nextInt();
user3=scnr.nextInt();




System.out.print("largest: " +largestNumber);
System.out.print("smallest: " +smallestNumber);
}
}





My errors:



LabProgram.java:12: error: illegal start of type
} else {
^
LabProgram.java:15: error: illegal start of type
return largest;
^
LabProgram.java:15: error: expected
return largest;
^
LabProgram.java:18: error: class, interface, or enum expected
public static int smallestNumber(int num1, int num2, int num3
^
LabProgram.java:21: error: class, interface, or enum expected
if ((num1 < num2)="" &&="">< num3))="">
^
LabProgram.java:23: error: class, interface, or enum expected
} else if (num2 < num3="" &&="" num2=""><>

^
LabProgram.java:25: error: class, interface, or enum expected
} else {
^
LabProgram.java:27: error: class, interface, or enum expected
}
^
LabProgram.java:29: error: class, interface, or enum expected
}
^
LabProgram.java:31: error: class, interface, or enum expected
public static void main(String[] args) {
^
LabProgram.java:33: error: class, interface, or enum expected
user1=scnr.nextInt();
^
LabProgram.java:34: error: class, interface, or enum expected
user2=scnr.nextInt();
^
LabProgram.java:35: error: class, interface, or enum expected
user3=scnr.nextInt();
^
LabProgram.java:39: error: class, interface, or enum expected
System.out.print("largest: " +largestNumber);
^
LabProgram.java:40: error: class, interface, or enum expected
System.out.print("smallest: " +smallestNumber);
^
LabProgram.java:41: error: class, interface, or enum expected
}
^
16 errors


Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here