+ 3
why this code is not printing ( kindly choose ) help pls
import java.util.Scanner; public class program{ public static void main (String[]args){ Scanner nnur = new Scanner(System.in); String j = nnur.nextLine(); if ( j == "yes") { System.out.println("kindly choose"); } else { System.out.println("Hi"); } }}
3 ответов
+ 9
if(j.equals ("yes"))
{}
//for ignoring capital and small letters ie... Yes & yes ... u can use ignore case ... see david's answer
+ 4
replace if (j=="hi") with the below one, always use equalsIgnoreCase() when comparing strings.
if (j.equalsIgnoreCase("hi"));
+ 2
thanks @DavidStark and @GauravAgarwal
finally it works..