Multiple subtraction test questions, detailed analysis, new output knowledge, and output
1 package com. baidu; 2 import java. util. iterator; 3 public class SubtractionzLoop {4 public static void main (String [] args) {5 final int NUMBER_OF_QUESTIONS = 6; // defines a constant, a computer path question; 6 int correctCount = 0; // The correct answer for calculation is a few; 7 int count = 0; // a total of several computations; 8 long startTime = System. currentTimeMillis (); // The time when the record starts to be generated 9 String output = ""; // The output String is null for 10 bytes input = new bytes (System. in); // enter the system scan keyboard to enter numbers; 11 1 2 while (count <NUMBER_OF_QUESTIONS) {13 // generate two random unit integers; 14 int number1 = (int) (Math. random () * 10); 15 int number2 = (int) (Math. random () * 10); 16 17 if (number1 <number2) {18 // compare the size for SWAp; 19 int temp = number1; 20 number1 = number2; 21 number2 = temp; 22} 23 // prompt the student to answer the question 24 System. out. println ("what is" + number1 + "-" + number2 + "? "); 25 int answer = input. nextInt (); // enter the corresponding result; 26 27 if (number1-number2 = answer) {28 // score the answer and display the result; 29 System. out. println ("your are current"); 30 correctCount ++; // Add the correct answer count 31 32} 33 else34 System. out. println ("your answer is wrong. \ n "+ number1 +"-"+ number2 +" shocould be "+ (number1-number2); 35 36 count ++; // added question Count 37 // 38 // 9-2 = 7 (correct) or 5 (wrong) 39 output + = "\ n" + number1 + "-" + number2 + "=" + Nswer + (number1-number2 = answer )? "Correct": "wrong"); 40} 41 42 long endTime = System. currentTimeMillis (); // record generation time 43 long testTime = endTime-startTime; // record test time 44 // Correct count is correctCount45 // \ nTest time is testTime/1000 second \ n output46 47 System. out. println ("Correct count is" + correctCount + "\ nTest time is" + testTime/1000 + "second \ n" + output); 48} 49 50}View Code
1 package com. baidu; 2 import java. util. iterator; 3 public class SubtractionzLoop {4 public static void main (String [] args) {5 final int NUMBER_OF_QUESTIONS = 6; // defines a constant, a computer path question; 6 int correctCount = 0; // The correct answer for calculation is a few; 7 int count = 0; // a total of several computations; 8 long startTime = System. currentTimeMillis (); // The time when the record starts to be generated 9 String output = ""; // The output String is null for 10 bytes input = new bytes (System. in); // enter the system scan keyboard to enter numbers; 11 1 2 while (count <NUMBER_OF_QUESTIONS) {13 // generate two random unit integers; 14 int number1 = (int) (Math. random () * 10); 15 int number2 = (int) (Math. random () * 10); 16 17 if (number1 <number2) {18 // compare the size for SWAp; 19 int temp = number1; 20 number1 = number2; 21 number2 = temp; 22} 23 // prompt the student to answer the question 24 System. out. println ("what is" + number1 + "-" + number2 + "? "); 25 int answer = input. nextInt (); // enter the corresponding result; 26 27 if (number1-number2 = answer) {28 // score the answer and display the result; 29 System. out. println ("your are current"); 30 correctCount ++; // Add the correct answer count 31 32} 33 else34 System. out. println ("your answer is wrong. \ n "+ number1 +"-"+ number2 +" shocould be "+ (number1-number2); 35 36 count ++; // added question Count 37 // 38 // 9-2 = 7 (correct) or 5 (wrong) 39 output + = "\ n" + number1 + "-" + number2 + "=" + Nswer + (number1-number2 = answer )? "Correct": "wrong"); 40} 41 42 long endTime = System. currentTimeMillis (); // record generation time 43 long testTime = endTime-startTime; // record test time 44 // Correct count is correctCount45 // \ nTest time is testTime/1000 second \ n output46 47 System. out. println ("Correct count is" + correctCount + "\ nTest time is" + testTime/1000 + "second \ n" + output); 48} 49 50}
1. The IO stream is used to process data transmission between devices. The Input stream (Input) can only read data from it, but cannot write data to it.
Output stream (Output): Only data can be written to it, but data cannot be read from it.
2. java operates on data through a stream,
3. java objects used for stream operations are all in the IO package.
4. streams are divided into two types by operation data: byte streams and byte streams; input streams and output streams by flow.