错题本
1.books1page91title5编计算器
package xsh.java.lx; import java.util.*; public class BooksPage91Title5 { public static void main(String[] args) { Scanner input=new Scanner(System.in); double total=0;//结果 System.out.println("请输入第一的操作数:"); double num1=input.nextDouble(); System.out.println("请输入第二的操作数:"); if(input.hasNextInt()){ double num2=input.nextDouble(); System.out.print("请输入操作符:"); String js=input.next(); switch(js){ case "+": System.out.println(total=(num1+num2)); break; case "-": System.out.println(total=(num1-num2)); break; case "*": System.out.println(total=(num1*num2)); break; case "/": System.out.println(total=(num1/num2)); break; default: break; } System.out.println("结果是:"+total); }else{ System.out.println("请输入正确数字"); } } }
错题原因:忘记了计算机重上倒下重左到右的运用
2.统计30岁以上人占得百分比
package java01; import java.util.Scanner; public class Books1Page124TitleSj2 { public static void main(String[] args) { Scanner input=new Scanner(System.in); double dsbl=0; double ds=0; for(int i=1;i<=10;i++){ System.out.println("请输入第"+i+"位顾客的年龄"); int age=input.nextInt(); if(age>30){ ds=ds+1; dsbl=ds/10; } } System.out.print("30岁以上的比例是:"+(dsbl*100)+"%"); System.out.print("30岁以下的比例是:"+(1-dsbl)*100+"%"); } }
3.正确输入5门课程的分数计算平均分,当输入是负数时提示重新输入
package java01; import java.util.*; public class Books1Page126TitleSl6 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); boolean isNegative=false;//不是负数 double avg; int sum = 0; for(int i=1;i<=5;i++){ System.out.println("请输入第"+i+"门课的成绩"); int score=input.nextInt(); sum=sum+score; if(score<0){ isNegative=true; break; } }//for结束 if(isNegative){ System.out.print("输入有误请重新输入:"); }else{ avg=sum/5; System.out.print("五门课的平均分是:"+avg); } } }
4.输入班级人数并计算80分以上人数百分比
package java01; import java.util.Scanner; public class Books1Page128TitleSl7 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.print("输入班级总人数:"); int total=input.nextInt(); double sum=0; for(int i=1;i<=total;i++){ System.out.print("请输入第"+i+"位学生的成绩"); int score=input.nextInt(); if(score<80){ continue; } sum=sum+1; }//for结束 double rate=(sum/total)*100; System.out.println("80分以上的人数是:"+sum); System.out.print("80分以上的人数比例是:"+rate+"%"); } }