Scanner Class in Java:-




This class exist under java.util package ,It is used to manage User Input Operation Under Console Screen.

hence it is also called input manager class in Java.

To take input from user's ,java provide System.in reference which will be handled by Scanner Class.


Scanner sc = new Scanner(System.in);


It will manage System.in input under Scanner  Object ,in above Statement sc is the Scanner Object.

After that we can type Scanner Object to other datatype.


int a = sc.nextInt();

float b = sc.nextFloat();

double d = sc.nextDouble();

String s = sc.next();

char ch = sc.next().charAt(0);

...............................................................................................................................................


import java.util.Scanner;

class SI
{
   public static void main(String args[])
   {
      Scanner sc = new Scanner(System.in);
      float p=12000,r=2,t=2,si;
      System.out.println("enter value for p");
      p=sc.nextFloat();
      System.out.println("enter value for r");
      r=sc.nextFloat();
      System.out.println("enter value for t");
      t=sc.nextFloat();
      si=(p*r*t)/100;
      System.out.println("Result is "+si);
   

   }


}



  

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post