+ 1

Text position

Hello, I have a Code in that I set a variable to a letter from the Alphabet. String chars = "abcdefghijklmnopqrstuvwxyzäöüß.,:;?-_()'=+/@"; Random rnd = new Random(); char buchstabe = chars.charAt(rnd.nextInt(chars.length())); Then i have an Input from the user. String antwort = scan.nextLine(); scan.close(); At least I want to set the random letter to a specific result if (buchstabe = "a") { result = ._.; } else { System.out.println("False"); } What do i Need to Change to make it possible? I Always get at the if Clip: Exception in thread "main" java.lang.Error: Unresolved compilation problems: The operator && is undefined for the argument type(s) char, String Type mismatch: cannot convert from String to char Type mismatch: cannot convert from String[] to String It isnt the full Code.

10th Aug 2019, 5:01 PM
Peter Möhle
Peter Möhle - avatar
2 Respostas
+ 1
Show full code, it will be useful. If statement require Boolean expression but you are only setting value. If(buchstabe == 'a') You should use 'a' instead of "a" because you want to compare chars. "a" - string 'a' - char
10th Aug 2019, 5:12 PM
Michal
Michal - avatar