I'm currently taking Java I and I have to write a program that reads 5 integers and determines and prints the largest and smallest numbers without using an array. I have to only use the if statements. I can't figure out how to make the if statement apply to 5 variables and manipulate all of them. I'm using the Deitel 8th edition How to Program book. I can't figure out how to make the if statement compare all five. This is due today and I have tried contacting my teacher and a classmate and neither have responded. Here is what I have so far:
import java.util.Scanner;
public class LargestAndSmallestIntegers
{
public static void main(String[] args)
{
Scanner input = new Scanner( System.in);
//set variables
int num1;
int num2;
int num3;
int num4;
int num5;
System.out.println(" Enter first ineger: " ); //prompt
num1 = input.nextInt();
System.out.println(" Enter second integer: " ); //prompt
num2 = input.nextInt();
System.out.println(" Enter third integer: " ); //prompt
num3 = input.nextInt();
System.out.println(" Enter fourth integer: " ); //prompt
num4 = input.nextInt();
System.out.println(" Enter fifth integer: " ); //prompt
num5 = input.nextInt();
if (num1 > num2)
System.out.printf("%d", num1);
}
}