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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JAVA四则运算(读写文件)

發(fā)布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JAVA四则运算(读写文件) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

完成時間:17:10

package 四則運算試題;import java.io.BufferedReader; import java.io.PrintStream; import java.util.Scanner; import java.io.FileReader; import java.io.IOException; public class jisuanti {public static void main(String[] args) throws IOException {int a1,a2;int b;int num=0;int i=0;//Scanner sc=new Scanner(System.in);String f[]=new String[4];f[0]="+";f[1]="-";f[2]="*";f[3]="/";int a[]=new int[100];//System.out.println("請選擇100以內(nèi)或1000以內(nèi)");//m=sc.nextInt()+1;//System.out.println("請輸入要產(chǎn)生的題數(shù)");//n=sc.nextInt();PrintStream out = System.out;PrintStream ps = new PrintStream("Test.txt");System.setOut(ps);for(i=0;i<3;i++){ a1=(int)(Math.random()*100);a2=(int)(Math.random()*100);b=(int)(Math.random()*4);System.out.println("第"+(i+1)+"題:"+a1+f[b]+a2+"=");System.out.println("*");switch(b) {case 0:a[i]=(a1+a2);break;case 1:a[i]=(a1-a2);break;case 2:a[i]=(a1*a2);break;case 3:a[i]=(a1/a2);break;}}ps.close();System.setOut(out);System.out.println("題目:");BufferedReader br = new BufferedReader(new FileReader("Test.txt"));String line = "";Scanner sc=new Scanner(System.in);int answer[]=new int[100];int m=0;while((line = br.readLine()) != null){if(line.charAt(0)=='*') {System.out.print("請輸入答案:");// System.out.println(a[m]);int n;n=sc.nextInt();answer[m]=n;if(answer[m]==a[m])num++;m++;}else {System.out.println(line);}}sc.close();br.close();System.out.println("共答對"+num+"題");} }

  

問題:問題卡在對比結(jié)果。

?

轉(zhuǎn)載于:https://www.cnblogs.com/zmh-980509/p/9966327.html

總結(jié)

以上是生活随笔為你收集整理的JAVA四则运算(读写文件)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。