84669 orang belajar
152542 orang belajar
20005 orang belajar
5487 orang belajar
7821 orang belajar
359900 orang belajar
3350 orang belajar
180660 orang belajar
48569 orang belajar
18603 orang belajar
40936 orang belajar
1549 orang belajar
1183 orang belajar
32909 orang belajar
闭关修行中......
import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Test { public static void main(String[] args) throws IOException { Test t = new Test(); t.waitInput(); System.out.println("Average Value:" + t.average()); } private double num1; private double num2; public void waitInput() throws IOException { while (true) { System.out.printf("Please enter two numbers:(Separated by spaces)\n"); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine(); String[] parts = line.trim().split("\s+"); if (parts.length < 2) { System.out.println("ERROR: incorrect input"); continue; } try { num1 = Double.parseDouble(parts[0]); num2 = Double.parseDouble(parts[1]); break; } catch (NumberFormatException e) { e.printStackTrace(); } } } public double average() throws IOException { return (num1 + num2) / 2; } }
Objek BufferedReader dijana setiap kali dalam gelung while dan tidak ditutup?
Objek BufferedReader dijana setiap kali dalam gelung while dan tidak ditutup?