Nejlepší odpověď
  
V Javě můžete ke čtení vstupu použít skener třídy a k tisku výstup System.out.
 Scanner scanner = new Scanner(System.in); 
 int n = scanner.nextInt(); // read an integer from input stream. 
 System.out.println(n) // print n 
Někdy však překročíte časový limit (TLE) kvůli výkonu skeneru. Místo toho můžete použít BufferedReader.
 class InputReader { 
  public BufferedReader reader; 
  public StringTokenizer tokenizer; 
  public InputReader(InputStream stream) { 
  reader = new BufferedReader(new InputStreamReader(stream), 32768); 
  tokenizer = null; 
  tokenizer = null; 
  } 
  public String next() { 
  while (tokenizer == null || !tokenizer.hasMoreTokens()) { 
  try { 
  tokenizer = new StringTokenizer(reader.readLine()); 
  } catch (IOException e) { 
  throw new RuntimeException(e); 
  } 
  } 
  return tokenizer.nextToken(); 
  } 
  public int nextInt() { 
  return Integer.parseInt(next()); 
  } 
   
  public long nextLong() { 
  return Long.parseLong(next()); 
  } 
 } 
Odpověď
Pokusím se to vysvětlit pomocí Rozzlobený profesor problém z HackerRank.
Následující kód načte ze System.in a vytiskne výstup, zbytek je samozřejmý:
 import java.io.*; 
 import java.util.*; 
 public class Solution { 
   
  public static void main(String[] args) { 
  Scanner in = new Scanner(System.in); 
  int t = in.nextInt(); 
  for (int i = 0; i < t; i++) { 
  int nstudent = in.nextInt(); 
  int threshold = in.nextInt(); 
  int[] arrival = new int[nstudent]; 
  for (int j = 0; j < nstudent; j++) { 
  arrival[j] = in.nextInt(); 
  } 
  algo(arrival, threshold); 
  } 
  } 
   
  public static void algo(int[] arrival, int threshold){ 
  //your implementation 
  } 
 }