Answers for "how to read input in java"

4

java read input from user

import java.util.Scanner; /* Required Import*/
public class reading{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in); // Create Reader 
    System.out.print("Enter Your Age"); // Ask the user for something
    int age = scan.nextInt(); // Read value from user
    System.out.print(age); // Output the value
  }
}
/*
  Java Reading Options:
  1_ reading int => nextInt();
  2_ reading char => next().charAt(0); Single Character
  3_ reading string => next();
  4_ reading double => nextDouble();
*/
Posted by: Guest on June-17-2021
6

java taking console input

String str = System.console().readLine();
Posted by: Guest on April-01-2020
33

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

how to use input in java

import java.util.*;
class a 
{
    void main ()
    {
        Scanner in = new Scanner(System.in);
      System.out.print("Please enter you age: ");
      int age = in.nextInt();
      System.out.print("Please enter today's date: ");
      int date = in.nextInt();
      System.out.print("Please enter current month: ");
      int month = in.nextInt();
      System.out.print("Please enter current year: ");
      int year = in.nextInt();
    }
}
// ENJOY!!!!!!!
Posted by: Guest on June-12-2021
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
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

Code answers related to "how to read input in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language