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

8th Feb 2022, 5:25 PM
Tony Jadesola
2 ответов
+ 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"))
8th Feb 2022, 5:32 PM
A͢J
A͢J - avatar
+ 1
Shaurya Kushwaha omg I can't believe I made a small mistake 😭😭
8th Feb 2022, 5:39 PM
Tony Jadesola