-4

I like to read from a console in Java. What is the most convenient way to do it for the sake of the processing of the input? For example I want to read a single char or an integer.

Marjan100
  • 306
  • 1
  • 2
  • 13

2 Answers2

1
import java.util.Scanner;

Scanner input = new Scanner(System.in);
int toBeRead = Integer.parseInt(input.nextLine());
MMelvin0581
  • 467
  • 3
  • 18
  • Be aware that `replace()` and `replaceAll()` are both slow because many many string objects are created inside the method call: https://stackoverflow.com/questions/6262397/string-replaceall-is-considerably-slower-than-doing-the-job-yourself – T Tse Apr 19 '18 at 19:10
0

import java.util.Scanner

Scanner sc=new Scanner(System.in); sc.nextInt();

Null
  • 26
  • 3