java scanner input int
// Java program to read data of various types using Scanner class.
import java.util.Scanner;
public class ScannerDemo1
{
public static void main(String[] args)
{
// Declare the object and initialize with
// predefined standard input object
Scanner sc = new Scanner(System.in);
// String input
String name = sc.nextLine();
// Character input
char gender = sc.next().charAt(0);
// Numerical data input
// byte, short and float can be read
// using similar-named functions.
int age = sc.nextInt();
long mobileNo = sc.nextLong();
double cgpa = sc.nextDouble();
// Print the values to check if the input was correctly obtained.
System.out.println("Name: "+name);
System.out.println("Gender: "+gender);
System.out.println("Age: "+age);
System.out.println("Mobile Number: "+mobileNo);
System.out.println("CGPA: "+cgpa);
}
}
Also in Java:
- how to create a circle in java
- how to remove a certain string in a arraylist java
- java create unmodifiable list
- labeled for loop in java
- how to get a user to add to an arraylist in java
- how to minimize jframe in java
- inheritance in java
- system.in example in java
- check if optional is empty java
- java get an int from a char
- android dismiss keyboard
- remove unused imports intellij
- how to open a webpage with java
- java collapse string array
- cgange background from button click java fx
- parsedouble java
- Error executing Maven. java.io.FileNotFoundException: The specified user settings file does not exist: /etc/java-8-openjdk
- mettre caractère de string en majuscule java
- sending a excel in an attachment in email java
- socket programming in java
- binary string to int java
- e
- how add strings together
- resurce leak java