+ 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"); } }}

21st Sep 2017, 9:16 AM
Raghav Khullar
Raghav Khullar - avatar
3 odpowiedzi
+ 9
if(j.equals ("yes")) {} //for ignoring capital and small letters ie... Yes & yes ... u can use ignore case ... see david's answer
21st Sep 2017, 10:07 AM
Changed
Changed - avatar
+ 4
replace if (j=="hi") with the below one, always use equalsIgnoreCase() when comparing strings. if (j.equalsIgnoreCase("hi"));
21st Sep 2017, 9:43 AM
D_Stark
D_Stark - avatar
+ 2
thanks @DavidStark and @GauravAgarwal finally it works..
22nd Sep 2017, 3:33 AM
Raghav Khullar
Raghav Khullar - avatar