Good afternoon
Given a nonnegative integer n and n nonnegative integers, indicate which of these numbers is the largest and the smallest.
So far I've only been able to find the biggest one that anyone can help My code below:
package exe10ficha1;
import javax.swing.JOptionPane;
public class Exe10ficha1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int num;
int nums;
int maior = 0;
int menor = 0;
int i;
int aux;
num = Integer.parseInt(JOptionPane.showInputDialog("Indique um valor"));
if (num > 0) {
for (i = 1; i <= num; i++) {
nums = Integer.parseInt(JOptionPane.showInputDialog("Indique um valor"));
if (nums <= 0) {
System.out.println("O valor e invalido");
System.exit(0);
}
if (nums >= maior) {
maior = nums;
} else {
menor = nums;
}
}
}
System.out.println("O maior e: " + maior);
System.out.println("O menor e: " + menor);
}
}