Hi, everyone . my name is sumon and i am from Bangladesh. i am a beginner in Java. i am practicing beginners level programming. I have faced a problem here. if anyone give me the solution then I will be glad.
I need help. can anyone tell me to control the loop. i don't want to use nested loop for this program. when i will type 'K' then it will get the right guess but when I will type else it will shows try again. but somehow the loop gives two time "try again " message here. kindly give me a solution without using nested loop. the code is here
public class Main { public static void main(String[] args) throws java.io.IOException { char ch, ignore, answer = 'K'; System.out.println("Guess the letter from A -Z Can you guess it? "); for (int i = 0; i < 4; ) { ch = (char) System.in.read(); if (ch == answer) { System.out.print("Right answer"); break; } else System.out.print(" try again "); i++; } } }