Header Ads

Reading a String

The String class represents character strings. All string literals in Java programs, such as "abc" , are implemented as instances of this class.Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared.


Reading a String
<
import java.util.Scanner;
public class ReadString {
 public static void main(String[] args) {
  System.out.println("enter a String: ");

  Scanner sc =new Scanner(System.in);
while(true){
String s=sc.nextLine();
               s=s.toLowerCase();
if(s.indexOf("hari")!=-1){
System.out.println("Hi,hari!");
}
else{
System.out.println("Who are you?");
}
break;
}
}

}


OutPut:
Enter a String:  hari
Hi,hari!

No comments

Powered by Blogger.