1 package com.baidu; 2 import java.util.Scanner; 3 public class SubtractionzLoop { 4 public static void main(String[] args) { 5 final int NUMBER_OF_QUESTIONS = 6; //定义一个常量,计算机道题目; 6 int correctCount = 0; //计算正确的答案是几个; 7 int count = 0; //计算一共有几个; 8 long startTime = System.currentTimeMillis(); //记录开始产生的时间 9 String output = " "; //输出字符串是空的 10 Scanner input = new Scanner(System.in); //输入 系统扫描键盘录入数字; 11 12 while(count<NUMBER_OF_QUESTIONS) { 13 //生成两个随机的单位数整数; 14 int number1 = (int)(Math.random()*10); 15 int number2 = (int)(Math.random()*10); 16 17 if(number1<number2) { 18 //比较大小进行交换; 19 int temp = number1; 20 number1 = number2; 21 number2 = temp; 22 } 23 //提示学生回答,计算问题 24 System.out.println("what is " + number1 + " - " + number2 + " ? "); 25 int answer = input.nextInt();//输入相应的结果; 26 27 if(number1-number2 == answer) { 28 //评分答案并显示结果; 29 System.out.println(" your are current "); 30 correctCount++; //增加正确的答案计数 31 32 } 33 else 34 System.out.println("your answer is wrong. "+ number1 + " - "+ number2 + " should be "+ (number1-number2)); 35 36 count++; //增加问题数 37 // 38 // 9 - 2 = 7(correct) or 5(wrong) 39 output+=" "+number1+"-"+number2+"="+answer+ ((number1-number2==answer)?"correct":"wrong"); 40 } 41 42 long endTime = System.currentTimeMillis(); //记录产生的时间 43 long testTime = endTime - startTime; //记录测试时间 44 //Correct count is correctCount 45 // Test time is testTime/1000 second output 46 47 System.out.println("Correct count is "+ correctCount + " Test time is " + testTime/1000 + "second " + output); 48 } 49 50 }
1 package com.baidu; 2 import java.util.Scanner; 3 public class SubtractionzLoop { 4 public static void main(String[] args) { 5 final int NUMBER_OF_QUESTIONS = 6; //定义一个常量,计算机道题目; 6 int correctCount = 0; //计算正确的答案是几个; 7 int count = 0; //计算一共有几个; 8 long startTime = System.currentTimeMillis(); //记录开始产生的时间 9 String output = " "; //输出字符串是空的 10 Scanner input = new Scanner(System.in); //输入 系统扫描键盘录入数字; 11 12 while(count<NUMBER_OF_QUESTIONS) { 13 //生成两个随机的单位数整数; 14 int number1 = (int)(Math.random()*10); 15 int number2 = (int)(Math.random()*10); 16 17 if(number1<number2) { 18 //比较大小进行交换; 19 int temp = number1; 20 number1 = number2; 21 number2 = temp; 22 } 23 //提示学生回答,计算问题 24 System.out.println("what is " + number1 + " - " + number2 + " ? "); 25 int answer = input.nextInt();//输入相应的结果; 26 27 if(number1-number2 == answer) { 28 //评分答案并显示结果; 29 System.out.println(" your are current "); 30 correctCount++; //增加正确的答案计数 31 32 } 33 else 34 System.out.println("your answer is wrong. "+ number1 + " - "+ number2 + " should be "+ (number1-number2)); 35 36 count++; //增加问题数 37 // 38 // 9 - 2 = 7(correct) or 5(wrong) 39 output+=" "+number1+"-"+number2+"="+answer+ ((number1-number2==answer)?"correct":"wrong"); 40 } 41 42 long endTime = System.currentTimeMillis(); //记录产生的时间 43 long testTime = endTime - startTime; //记录测试时间 44 //Correct count is correctCount 45 // Test time is testTime/1000 second output 46 47 System.out.println("Correct count is "+ correctCount + " Test time is " + testTime/1000 + "second " + output); 48 } 49 50 }
1.IO流是用来处理设备之间的数据传输;输入流(Input):只能从中读取数据,而不能向其写入数据
输出流(Output):只能向其写入数据,而不能从中读取数据
2.java对数据的操作是通过流的方式、
3.java用于操作流的对象都在IO包中。
4.流按照操作数据分为两种:字节流和字符流;按照流向分为输入流和输出流