Test java programs that read from stdin and write to stdout

后端 未结 3 1465
误落风尘
误落风尘 2020-12-11 03:38

I am writing some code for a programming contest in java. The input to the program is given using stdin and output is on stdout. How are you folks testing programs that work

3条回答
  •  有刺的猬
    2020-12-11 03:41

    EDITED: Sorry I misread your question.

    Read with scanner or bufferedreader, The latter is much faster than the former.

    Scanner jin = new Scanner(System.in);
    
    BufferedReader reader = new BufferedReader(System.in);
    

    Write to stdout with print writer. You can also print directly to Syso but this is slower.

    System.out.println("Sample");
    System.out.printf("%.2f",5.123);
    
    PrintWriter out = new PrintWriter(System.out);
    out.print("Sample");
    out.close();
    

提交回复
热议问题