+ 1
Trying to make if statement with string condition, where was i wrong?
import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String n = input.nextLine(); if (n=="y") {System.out.println("yes");} if (n=="n") {System.out.println("no");} } }
2 Respostas
+ 2
you cannot compare like this unless they are from String class make it n= new S tring
or you can use n.equals("yes")
or you can import libraries that contains methods to equate
+ 1
thank you, it worked :)