0
Im a beginner plz help to solve this
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String x=sc.nextLine(); if(x=hi){ System.out.println ("hi"); } else{ System.out.println ("do something"); } } }
3 Answers
+ 3
/* dont use == to compare strings use below statement so if your string is case sensitive it will be ignored but if you want it to be exactly "hi" then use @Niush statement */
if(x.equalsIgnoreCase("hi");
+ 2
one more doubt if its integer then
if (x=1) is correct or if (x .equals(1))
+ 2
Comparing int use this > (x==1)
Comparing String use this > (x.equals("hi"))