标签:vat demo print sys exti ret 语文 java stat
H学校的领导主任决定分析一下今年所有N名学生的考试成绩,从中找出偏科的学生,考试成绩包含语文,数学,英语三门课程的分数,已知偏科的定义是:某一门课程的分数大于等于90,并且另外两门的分数小于等于70。
请你求出一共有多少名偏科的学生。
输入第一行包含一个整数N。
以下N行每行包含三个整数,Ai,Bi,Ci,依次是语文,数学,英语的分数。
1<=N<=10000
0<=Ai,Bi,Ci<=100
输出
一个整数代表答案
首先应该先写出学生类:
public class StudentDemo { private int lanGrade;//语文成绩 private int mathGrade;//数学成绩 private int engGrade;//英语成绩 public StudentDemo(int lanGrade,int mathGrade,int engGrade){ this.lanGrade = lanGrade; this.engGrade = engGrade; this.mathGrade = mathGrade; } public int getLanGrade() { return lanGrade; } public void setLanGrade(int lanGrade) { this.lanGrade = lanGrade; } public int getMathGrade() { return mathGrade; } public void setMathGrade(int mathGrade) { this.mathGrade = mathGrade; } public int getEngGrade() { return engGrade; } public void setEngGrade(int engGrade) { this.engGrade = engGrade; } @Override public String toString() { return "StudentDemo{" + "lanGrade=" + lanGrade + ", mathGrade=" + mathGrade + ", engGrade=" + engGrade + ‘}‘; } }
创建成绩类:(判断)
import java.util.Scanner; public class GradeTest { private StudentDemo[] studentDemos; private int studentNum; private Scanner sc; public GradeTest(){ this.sc = new Scanner(System.in); this.studentNum = 0; this.studentDemos = new StudentDemo[1000]; this.studentDemos[this.studentNum++] = new StudentDemo(0,0,0); } public static void main(String[] args) { GradeTest gd = new GradeTest(); gd.setGrade(); int num = gd.search(); System.out.println("偏科人数:"+num); } private void setGrade() { System.out.println("请输入学生个数:"); int num = sc.nextInt(); System.out.println("请输入学生成绩(成绩大于等于0小于等于100):"); int i = 1; while (i <= num) { int lanGrade = sc.nextInt(); int mathGrade = sc.nextInt(); int engGrade = sc.nextInt(); if (i == studentNum) { studentDemos[this.studentNum++] = new StudentDemo(lanGrade, mathGrade, engGrade); } i++; } } public int search() { int count = 0; for (int i = 0; i < this.studentNum; i++) { if ((studentDemos[i].getEngGrade() >= 90 && studentDemos[i].getLanGrade() <= 70 && studentDemos[i].getMathGrade() <= 70) || (studentDemos[i].getLanGrade() >= 90 && studentDemos[i].getEngGrade() <= 70 && studentDemos[i].getMathGrade() <= 70) || (studentDemos[i].getMathGrade() >= 90 && studentDemos[i].getLanGrade() <= 70 && studentDemos[i].getEngGrade() <= 70)) { count++; } } return count; } }
运行结果:
标签:vat demo print sys exti ret 语文 java stat
原文地址:https://www.cnblogs.com/128-cdy/p/11921624.html