Escreví um programa com o seguinte código:
/**
- Title : RandomN.java
- Author : Filipe Jardim de Almeida
- Version : 3.00 2007/11/14
*/
public class RandomN {
public static void main(String[] args)
throws java.io.IOException {
char LeSec, Resp, alfabeto[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'z'};
int rI = 0 + (int)(Math.random() * 23);
int i;
LeSec = alfabeto[rI];
System.out.println("** Jogo 'advinhe a letra' V3.00 ** \nAdvinhe qual letra eu estou pensando?\nVoce tem 10 tentativas:");
//System.out.println(LeSec);
for (i = 0; i <= 10; ) {
Resp = (char) System.in.read();
i++;
if (LeSec == Resp) {
System.out.println("BLZ! Vc acertou!!!");
i = 11;
}
else if (Resp > LeSec) System.out.println("N, vc chutou ALTO d+!");
else if (Resp < LeSec) System.out.println("N, vc chutou BAIXO d+!");
else System.out.println("Tilt");
}
}
}
Entretanto a execução é sempre algo do tipo:
C:\Documents and Settings\filipe.almeida\Meus documentos\CURSO - JAVA\exercícios\Livro - A beginner’s Guide>java RandomN
** Jogo ‘advinhe a letra’ V3.00 **
Advinhe qual letra eu estou pensando?
Voce tem 10 tentativas:
a
N, vc chutou BAIXO d+!
N, vc chutou BAIXO d+!
N, vc chutou BAIXO d+!
a
N, vc chutou BAIXO d+!
N, vc chutou BAIXO d+!
N, vc chutou BAIXO d+!
a
N, vc chutou BAIXO d+!
N, vc chutou BAIXO d+!
N, vc chutou BAIXO d+!
N, vc chutou BAIXO d+!
Pq ele faz isso? pq o loop executa 3vezes ao mesmo tempo?
Obrigado por qualquer ajuda!