Java program of taking Input.

Hi,

Today we are going to learn to take input in Java.

import java.lang.*

class Solution

{

public static void main(String arg[])

{

Scanner sc = new Scanner (System.in);

String a =sc.nextLine();

int b =sc.nextInt();

Double d = sc.nextDouble();

System.out.println(“Value of String is :”+a);

System.out.println(“Value of Integer is:”+b);

System.out.println(“Value of Double is:”+d);

}

So in the Above program we take input in Java using the Scanner Class Utility.

Inorder to take input for various Datatype we need to use scanner object as

For Integer :

nextInt()

For Double:

nextDouble()

For Boolean:

nextBoolean()

For String

nextLine() or Simply next()

Compile the program and see the output

Advertisements