Answers for "how to get an input in java"

11

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
Posted by: Guest on May-14-2020
2

how to get user input in java

import java.util.*;  
class UserInputDemo   
{  
public static void main(String[] args)  
{  
Scanner sc= new Scanner(System.in);    //System.in is a standard input stream  
System.out.print("Enter first number- ");  
int a= sc.nextInt();  
System.out.print("Enter second number- ");  
int b= sc.nextInt();  
System.out.print("Enter third number- ");  
int c= sc.nextInt();  
int d=a+b+c;  
System.out.println("Total= " +d);  
}  
}  
Posted by: Guest on December-09-2020
7

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();
Posted by: Guest on January-05-2020
1

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); 
}
Posted by: Guest on September-23-2020
1

read input in java

3 ways to read input from console in java
-----------------------------

1. Using BufferedReader Class
2. Using Scanner Class
3. Using Console Class 

//bufferedreader class

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
...
public static void main(String[] args) throws IOException
...
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();

//Scanner class

import java.util.Scanner;
...

String name = new Scanner(System.in);

//Console class:

String name = Syste.console().readLine();
Posted by: Guest on March-01-2021

Code answers related to "how to get an input in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language