Solved programming problem

How to Scan in Java.

Source code

package scan;

import java.util.Scanner; ///for scan any thing you have to import this

public class Scan 

{

   

    public static void main(String[] args)

    {

        String name;

        int id;

        double cgpa; 

        

        Scanner sc = new Scanner(System.in); //create an scanner object

       

        ///input

        name = sc.nextLine();

        id = sc.nextInt();

        cgpa = sc.nextDouble();

        

        ///print

        System.out.println("Name: "+name+"
ID: "+id+"
CGPA: "+cgpa);     

       

    }

    

}

Output

Sabit

5

3.5

Name: Sabit

ID: 5

CGPA: 3.5

Join the discussion

Add your comment