Getting Input, Conditional Constructs, Array, Command Line

Using BufferedReader and JoptionPane, ask for 10 numbers from the user. Use an array to store the values of these 10 numbers. Output on the screen the number with the greatest value.

//BufferedReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Exercise5A {

public static void main(String[] args) {
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
int[] num = new int[10];
int counter;
int max = 0;
int totalnumber = 10;

for(counter = 0; counter max)){
max = num[counter];
}
}

System.out.println(“\nThe number with the greatest value is ” + max);
}

}

//JoptionPane
import javax.swing.JOptionPane;

public class Exercise5B {

public static void main(String[] args) {
int[] num = new int[10];
int counter;
int max = 0;
int totalnumber = 10;

for(counter = 0; counter max)){
max = num[counter];
}
}

JOptionPane.showMessageDialog(null,”The number with the greatest value is ” + max);
}

}

Leave a comment