java怎么样无限循环_java 为什么运行之后会无限循环。。

packagelianxi;importjava.util.*;importjava.util.Scanner;publicclasszuoye{publicstaticvoidmain(String[]args){ArrayLista=newArrayList();StuManagesm=newStuManage();Scannerin...

package lianxi;

import java.util.*;

import java.util.Scanner;

public class zuoye

{

public static void main(String[] args)

{

ArrayList a=new ArrayList();

StuManage sm=new StuManage();

Scanner input=new Scanner(System.in);

System.out.println("请选贼您要进行的操作:");

System.out.println("1.添加学生信息:");

System.out.println("2.查询学生成绩:");

System.out.println("3.查询学生编号:");

System.out.println("4.删除学生信息:");

String operType=input.next();

while(true)

{

if(operType.equals("1"))

{

sm.addStu();

}

else if(operType.equals("2"))

{

sm.showScore();

}

else if(operType.equals("3"))

{

sm.showstuNo();

}

else if(operType.equals("4"))

{

sm.delStu();

}

else if(operType.equals("0"))

{

System.exit(0);

}

}

}

}

class StuManage

{

ArrayList a=null;

public StuManage()

{

a=new ArrayList();

}

public void addStu()

{

Scanner input=new Scanner(System.in);

System.out.println("请输入学生编号:");

String stuNo=input.next();

System.out.println("请输入学生成绩:");

float score=input.nextFloat();

Stu stu=new Stu(stuNo,score);

a.add(stu);

}

public void showScore()

{

Scanner input=new Scanner(System.in);

System.out.println("请输入学生编号:");

String stuNo=input.next();

for(int i=0;i

{

Stu stu=(Stu)a.get(i);

if(stu.getStuNo().equals(stuNo))

{

System.out.println("学生成绩是:"+stu.getScore());

}

}

}

public void showstuNo()

{

Scanner input=new Scanner(System.in);

System.out.println("请输入学生成绩:");

float score=input.nextFloat();

for(int i=0;i

{

Stu stu=(Stu)a.get(i);

if(stu.getScore()==score)

{

System.out.println("学生的编号是:"+stu.getStuNo());

}

}

}

public void Count()

{

int good=0;

int bad=0;

for(int i=0;i

{

Stu stu=(Stu)a.get(i);

if(stu.getScore()>60&&stu.getScore()<=100)

{

good+=1;

}else if(stu.getScore()<60&&stu.getScore()>=0)

{

bad+=1;

}

}

System.out.println("及格学生人数是:"+good+" 不及格人数是:"+bad);

}

public void delStu()

{

Scanner input=new Scanner(System.in);

System.out.println("请输入学生的编号:");

String stuNo=input.next();

for(int i=0;i

{

Stu stu=(Stu)a.get(i);

if(stu.getStuNo().equals(stuNo))

{

a.remove(i);

System.out.println("----------已删除信息---------");

}

}

}

}

class Stu

{

private String stuNo;

private float score;

public String getStuNo() {

return stuNo;

}

public void setStuNo(String stuNo) {

this.stuNo = stuNo;

}

public float getScore() {

return score;

}

public void setScore(float score) {

this.score = score;

}

public Stu(String stuNo,float score)

{

this.stuNo=stuNo;

this.score=score;

}

}

记得之前写还好用,重新写突然找不出问题了,新手刚学

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值