Heading

Thursday, September 19, 2013

Reading String and integer using scanner

import java.util.Scanner;
public class CharIndex
{
 public static void main(String... s)
 {
 Scanner sc=new Scanner(System.in);

 System.out.println("Reading String with Spaces");
 System.out.println("Enter your String:");
 String str=sc.nextLine();
 System.out.println("Entered String are:"+str+"\n");

 System.out.println("Reading Integer Value");
 System.out.println("Enter your Number:");
 int num=sc.nextInt();
 System.out.println("Entered Number are:"+num);

 System.out.println("Reading String up to Space");
 System.out.println("Enter your String:");
 String str1=sc.next();
 System.out.println("Entered String are:"+str1+"\n");



 }
}

Output:


G:\company\java programs>javac CharIndex.java

G:\company\java programs>java CharIndex
Reading String with Spaces
Enter your String:
v v v veera
Entered String are:v v v veera

Reading Integer Value
Enter your Number:
143
Entered Number are:143
Reading String up to Space
Enter your String:
amrutha m
Entered String are:amrutha

No comments:

Post a Comment