Given a sequence of integers (read via Scanner
), determine the smallest of these values.
My code:
import java.util.Scanner;
public class MenorValorSequencia {
public static void main (String args []) {
Scanner sc = new Scanner (System.in);
int [] variavel = new int [10];
for (int i = 0; i<=9; i++) {
variavel[i] = sc.nextInt();
}
int menorValor = 0;
for (int i = 0; i<=9; i++) {
if (variavel[i]<menorValor) {
menorValor = variavel[i];
}
System.out.println (menorValor(i)); // erro: não pode achar variável menorvalor
}
}
}
Can the Java code for this problem be done like this?
Can someone please fix what's wrong?