日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java第二次考试

發布時間:2024/1/17 java 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java第二次考试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼

package sizeyunsuan; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Random; import java.util.Scanner; public class SiZe {@SuppressWarnings("unused")public static void main(String[] args) throws FileNotFoundException {String[] operate = new String[] { "+", "-", "*", "/" };//定義運算符數組int[] numbers = new int[100];//定義數字部分數組for (int i = 1; i <= 100; i++) {numbers[i - 1] = i;}Random rand = new Random();//定義隨機數@SuppressWarnings("resource")Scanner in = new Scanner( System.in );String fiilename ="d:/shuchu.txt";int operand1 = 0 ;int operand2 = 0;int operator;int result;int count=0; //統計正確的題目數量int i;duqu[] cal = new duqu[100]; //30道題目//隨機題目并顯示序號與題目for( i=0; i<100; i++ ){operator = rand.nextInt(4)+1;switch( operator ){case 1:operand1 = rand.nextInt(100);operand2 = rand.nextInt(100);break;case 2: //減法不出現負數operand1 = rand.nextInt(100);operand2 = rand.nextInt( operand1 );break;case 3: //乘除范圍更小operand1 = rand.nextInt(10);operand2 = rand.nextInt(10);break;case 4:operand2 = rand.nextInt(9)+1;operand1 = rand.nextInt(81-operand2)+operand2;break;}System.out.print( (i+1) +" ");cal[i] = new duqu( operand1, operator, operand2);cal[i].manager();if(i==0)duqu.flushFile(fiilename);duqu.OutputFile(fiilename,cal[i]);PrintStream out=System.out;}} } package sizeyunsuan;import java.io.*; public class duqu {private int operator; //操作數private int operand1; //操作數前面的數private int operand2; //操作數后面的書private int result; //運算結果,除法結果取整數部分private int statistics; //統計正誤private String str; //記錄題目public int getResult(){return result;}public int getStatistics(){ return statistics;}public duqu( int operand1 , int operator , int operand2 ){this.operand1 = operand1;this.operator = operator;this.operand2 = operand2;}public void manager(){switch(operator){case 1:str = operand1 +" + " + operand2 +" = ";result = operand1 + operand2;break;case 2:str = operand1 +" - " + operand2 +" = ";result = operand1 - operand2;break;case 3:str = operand1 +" * " + operand2 +" = ";result = operand1 * operand2;break;case 4:str = operand1 +" / " + operand2 +" = ";result = operand1 / operand2;break;}System.out.println(str);}public void judge( int result ){ //判斷正誤if( this.result == result){statistics = 1; //正確為1 }elsestatistics = 0; //錯誤為0 }public static void OutputFile(String filename,duqu cal){@SuppressWarnings("unused")File file = new File(filename);FileWriter fw = null;try {fw = new FileWriter(filename,true);} catch (IOException e) {e.printStackTrace();}PrintWriter p = new PrintWriter(fw);p.println(cal.str);p.close();try {fw.close();} catch (IOException e) {e.printStackTrace();}}public static void flushFile(String filename){File file = new File(filename);FileWriter fw;try {fw = new FileWriter(file);fw.write("");fw.flush();fw.close();} catch (IOException e) {// TODO Auto-generated catch block e.printStackTrace();}}}

于下午四點四十完成

總結:主要自己對于緩沖流導入文本文件夾,輸出文本文件夾,不太理解,一直困于此處,對于四則運算的正誤判斷也有些許的疑問,然后通過百度查閱,以及詢問同學弄懂了自己不是很會的地方,感覺自己在這次課堂測驗上學到了很多

轉載于:https://www.cnblogs.com/love-nan/p/9964919.html

總結

以上是生活随笔為你收集整理的Java第二次考试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。