Wednesday, 9 October 2013

Program for Scanner Input

//Program for Scanner Input
//Developed by Ahlam Ansari

import java.util.*;

class ScnnerInput
{
    public static void main (String ahlam[])
    {
        int intData;
        String stringData;
        float floatData;
        char c;       
        //1st step- create obj of scanner class
        Scanner scan = new Scanner( System.in );

        //2nd -accept data
        System.out.println( "enter the string, integer, float");
        stringData = scan.nextLine();
        intData = scan.nextInt();
        floatData = scan.nextFloat();
        c=scan.next().charAt(0);
        System.out.println( "IntData = " + intData + " FloatData = " + floatData + " StringData = " + stringData + "Chardata= "+c);
    }
}

/*
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>javac ScnnerInput.java

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java ScnnerInput
enter the string, integer, float
Ahlam
12
1.2
@
IntData = 12 FloatData = 1.2 StringData = AhlamChardata= @

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>
*/

No comments:

Post a Comment