+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.

8/10/2019 5:01:22 PM

Peter Möhle

2 Answers

New Answer

+2

@Peter Möhle Can't say much but here if(buchstabe = "a") 1. first thing "=" is an assignment operator, you probably wanted "==" operator 2. lhs is of type char where as "a" is a String. Try fixing these first.

+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