随机生成10道100以内加法练习题,一道题十分,最后生成所得分数 import java.util.Scanner; public class Addition { public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("答对一道加十分,答错一题不扣分,共十题"); int score=0; int i; for(i=1;i<=10;i++){ int a=(int)(Math.random()*100); int b=(int)(Math.random()*100); int result=a+b; System.out.println("("+i+")"+a+"+"+b+"=?"); System.out.println("算吧"); int num=scan.nextInt(); if(num==-1){ break; }else if(num==result){ System.out.println("答对了"); score++; }else{ System.out.println("答错了"); } System.out.println("目前答对"+score+"道"); } if(i==10){ System.out.println("总分为:"+score*10); } } }
java初学者代码练习
最新推荐文章于 2024-08-09 23:10:01 发布