+ 1
Java problem with char
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("guess the letter"); String answer = scanner.nextLine(); if(answer ="name"){ System.out.println("right!"); } } It says string cannot be converted to boolean.i used char in the first place, it said the same error.what am I missing }
2 Respuestas
+ 7
Tony Jadesola
Single equal (=) is user to assign value
Double equal (==) is used to compare value but you should not use == for comparison.
Use equals method like:
if(answer.equals("name"))
+ 1
Shaurya Kushwaha omg I can't believe I made a small mistake 😭😭