Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to take input in java

Scanner sc = new Scanner(System.in);  // Create a Scanner object
String userName = sc.nextLine();//read input string
int age = sc.nextInt(); //read input integer
long mobileNo = sc.nextLong(); //read input long
double cgpa = sc.nextDouble(); //read input double
System.out.println(userName);//output 
Comment

java get input

Scanner sc = new Scanner(System.in);
String s = sc.next();
int n = sc.nextInt();
double d = sc.nextDouble();
float f = sc.nextFloat();

// more fast way
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine(); // read line
int c = br.read();        // read single char
Comment

how to input in java

import java.util.Scanner;
...
  Scanner console = new Scanner(System.in);
  int num = console.nextInt();
  console.nextLine() // to take in the enter after the nextInt() 
  String str = console.nextLine();
Comment

how to read input in java

//For continues reading a line
import java.util.Scanner; 

Scanner in = new Scanner(System.in); 
while(in.hasNextLine()) {
   String line = in.nextLine();
   System.out.println("Next line is is: " + line); 
}
Comment

java get input


import java.util.Scanner; 
//...
Scanner scan = new Scanner(System.in);
String s = scan.next();
int i = scan.nextInt();

Comment

how to input in java

import java.util.*; //or java.util.scanner
Scanner doit = new Scanner(System.in);//Name the scanner
System.out.println("Username:");//It will specify username
String username = doit.next();//Use scanner and add .next for string .nextInt for int and follows
Comment

get input in java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Sample {

    public static void main(String[] args) {
        BufferedReader datain = new BufferedReader(new InputStreamReader(System.in));
        String name = "";
        System.out.print("Enter your name:");
        try {
            name = datain.readLine();
        } catch (IOException e) {
            System.out.print("Error");

        }
        System.out.println("Hello! " + name + "!");
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: java create new thread 
Java :: java 8 filter first 
Java :: spring boot mongodb update subdocument 
Java :: space in java 
Java :: replace all punctuation in string java 
Java :: java substring 
Java :: java negative infinity 
Java :: convert int to hex java 
Java :: try catch out of bounds exception java 
Java :: array to arraylist java 
Java :: android change checkbox color 
Java :: remove extra spaces java 
Java :: java logger error 
Java :: language of minecraft 
Java :: how to access variable from another class in java 
Java :: how to resize image in android programmatically 
Java :: cosinus-1 java 
Java :: java convert LocalDateTime to long 
Java :: inline arraylist initialization java 
Java :: arraylist java 
Java :: in place transpose in a matrix in java 
Java :: wait random time java 
Java :: how to use input in java 
Java :: select in selenium java 
Java :: set java home sdk macbook 
Java :: how to overwrite a text file in java 
Java :: matrix multiplication in java 
Java :: James Gosling 
Java :: double quotes in string java 
Java :: how to initialize bigdecimal in java 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =