How to take user input in JAVA programming


////This program show you how to take user input in JAVA
///For user input you need to create a scanner.......


package SolveProblem;

import java.util.Scanner;

public class UserInput {
    //static Scanner myScanner=new Scanner(System.in);
    //You should also create scanner in this section;
    public static void main(String[] args) {
        Scanner myScanner=new Scanner(System.in);
       
        int a,b;
       
        a=myScanner.nextInt();////For integer input.........
        b=myScanner.nextInt();
       
       
        double x;
        x=myScanner.nextDouble();////For double input..........
       
        String str=new String();
       
        str=myScanner.nextLine();////For string input
       
       
        float f;
       
        f=myScanner.nextFloat();////For float input
       
    }

}

No comments:

Post a Comment