Answers for "read from input 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
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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language