What's new for me ? Java
05/05/2019
Types to read input from user:
Input a string and a number using BufferedReader:
InputStream inputStream = System.in;
Reader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String name = bufferedReader.readLine(); //Read a string from the keyboard
String sAge = bufferedReader.readLine(); //Read a string from the keyboard
int nAge = Integer.parseInt(sAge); //Convert the string to a number.
A more compact version of the previous example:
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
String sAge = reader.readLine();
int nAge = Integer.parseInt(sAge);
Even more compact using Scanner :
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
int age = scanner.nextInt();
Shortcuts in IntelliJ Idea:
- psvm + Tab = public static void main(String[] args)
- sout + Tab = System.out.println();
Comments
Post a Comment