-5
Good afternoon
Given a non-negative integer n and n non-negative integers, indicate which of these numbers is the largest and which the smallest.
So far I’ve only been able to find the biggest 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);
}
}
Would that be Greater and lesser number ?
– rray
Not for example
– Max Tag
type 3 numbers 3,1,2 in the final result appears The largest and 3 the smallest and 2
– Max Tag
if (nums >= bigger) { smaller = bigger; bigger = nums; } Else { smaller = nums; ;}
– Marco Souza
This is not working
– Max Tag