我需要用Java开发奖学金申请。我需要在输出中打印成功的应用程序。
为什么如果我是第二个人,此代码中的计数器不会增加?
import java.util.Scanner;
import java.util.LinkedList;
public class Main
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
Application a = new Application();
LinkedList lList = new LinkedList();
boolean bEligible = false;
int scholarship;
int scholarshipAmount = 500000;
int setiStudyLevel;
int counter;
while(scholarshipAmount != 0)
{
counter = 1;
System.out.println("");
System.out.println("**Welcome to scholarship applications offered by Smart Foundation**");
System.out.println("");
System.out.println("");
System.out.println("Please Enter Your Name");
a.setsName(input.next());
System.out.println("1–Pre Diploma, 2–Diploma, 3–Degree");
System.out.println("Please Enter Your Study Level");
a.setiStudyLevel(input.nextInt());
System.out.println("Please Enter Your Personality Score");
a.setiPersonalityScore(input.nextInt());
System.out.println("Please Enter Your Parents Income");
a.setdParentsIncome(input.nextDouble());
String sName = a.getsName();
int iStudyLevel = a.getiStudyLevel();
int iPersonalityScore = a.getiPersonalityScore();
double dParentsIncome = a.getdParentsIncome();
if (iStudyLevel == 1)
{
scholarship = 15000;
scholarshipAmount = scholarshipAmount - scholarship;
}
else if (iStudyLevel == 2)
{
scholarship = 50000;
scholarshipAmount = scholarshipAmount - scholarship;
}
else if (iStudyLevel == 3)
{
scholarship = 500000;
scholarshipAmount = scholarshipAmount - scholarship;
}
System.out.println("");
System.out.println("");
System.out.println("*****Result*****");
System.out.println("Name:"+sName);
System.out.println("1–Pre Diploma, 2–Diploma, 3–Degree");
System.out.println("Study Level:"+iStudyLevel);
System.out.println("Personality Score:"+iPersonalityScore);
System.out.println("Parents Income:"+dParentsIncome);
if(iPersonalityScore <=90)
{
if(dParentsIncome >=3000)
{
System.out.println("YOU ARE NOT ELIGIBLE FOR SCHOLARSHIP ");
}
else
{
System.out.println("YOU ARE ELIGIBLE FOR SCHOLARSHIP ");
bEligible = true;
}
}
else
{
System.out.println("YOU ARE ELIGIBLE FOR SCHOLARSHIP ");
}
System.out.println("");
System.out.println( "RM"+(scholarshipAmount)+" left!!");
System.out.println("");
if (scholarshipAmount <= 0)
{
System.out.println(" Scholarship Quota is Full!");
}
counter++;
System.out.println(counter);
}
}
}
答案 0 :(得分:1)
问题是您在每个循环中将计数器重置为1
改变这个:
while(scholarshipAmount != 0)
{
counter = 1;
到这个
int counter = 1;//or maybe 0
while(scholarshipAmount != 0)
{
答案 1 :(得分:0)
你的循环应该是,
while(scholarshipAmount > 0)
{
//remaining code