Advertisement
H4cktz

Exercício JAVA Lista05_n10

Oct 18th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. 10. Escrever um algoritmo que lê um vetor 80 valores do tipo inteiro. Encontre o menor elemento e a sua posição no vetor e escreva: "O menor elemento do vetor é = ... e a sua posição é ... ".
  2.  
  3. import java.util.Scanner;
  4. public class Lista05_n10 {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         int [] vet = new int [80];
  8.         int menor = 0;
  9.         for (int i=0; i < vet.length;i++){
  10.             System.out.print("Digite um número inteiro");
  11.             vet[i] = scan.nextInt();
  12.         }
  13.         for (int i=1; i<vet.length; i++){
  14.             if(vet[i]<vet[menor]){
  15.                 menor = i;
  16.             }
  17.         }
  18.         System.out.print("O menor elemento do vetor é = "+vet[menor]+" e a sua posição é " +menor+".");
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement