Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package desafiosEuler;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Menornumero {
  6.  
  7. public static void main(String[] args) {
  8. int n;
  9.  
  10. Scanner sc = new Scanner(System.in);
  11. Scanner hue = new Scanner(System.in);
  12. System.out.println("Digite a quantidade de números: ");
  13. n = sc.nextInt();
  14. int[] vetor = new int[n+1];
  15. int[] menor = new int[1];
  16. vetor[0] = 2147483647;
  17. for(int i = 0; i < n; i++) {
  18. System.out.println("Digite o numero de ordem "+(i+1)+" : ");
  19. vetor[i+1] = sc.nextInt();
  20. vetor[i+1] = metodo(vetor[i], vetor[i + 1]);
  21. }
  22. System.out.println("");
  23. System.out.println("O menor número é "+vetor[n]+". E ele estava na posição de ordem: "+n);
  24. }
  25. public static int metodo(int x1, int x2) {
  26. int z = 0;
  27. if(x1 > x2) {
  28. z = x2;
  29. }
  30. if(x1 < x2) {
  31. z = x1;
  32. }
  33. return z;
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement