java - while循环不循环

标签 java while-loop

嗨,我正在练习java,刚刚学习java几天。我需要将500000的奖学金金额减去100000,但我似乎被困在400000上并且它不会继续。我的代码有什么问题请有人帮助我。提前致谢。

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 = 100000;
      int scholarshipAmount = 500000;
      int amount;

      while(scholarshipAmount != 0)
      {
         System.out.println("Please enter name");
         a.setsName(input.nextLine());

         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 Incomee");
         a.setdParentsIncome(input.nextDouble());

         String sName = a.getsName();
         int iStudyLevel = a.getiStudyLevel();
         int iPersonalityScore = a.getiPersonalityScore();
         double dParentsIncome = a.getdParentsIncome();

         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(sName);
         System.out.println(iStudyLevel);
         System.out.println(iPersonalityScore);
         System.out.println(dParentsIncome);

         amount = scholarshipAmount - scholarship;

         System.out.println(amount);
      }
   }
}

最佳答案

您永远不会更改scholarshipAmount金额

你需要这样做

 scholarshipAmount = scholarshipAmount - scholarship;

然后您需要更改此设置

System.out.println(amount);

System.out.println(scholarshipAmount );

关于java - while循环不循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24000905/

相关文章:

Ruby:编写一个一直运行到资源耗尽的循环程序?

c - C 中的 while 循环没有中断

python - While 循环语句 - 不同的答案

java - Spring Boot 将 yaml 列表加载为 map

c - 如何将 char** 中的每个字符串打印到 printf()?

java - 在文件中的每个单词后添加空格 (Java)

java - 在 Java 中创建类数组

c - 使用链接列表时 While 循环失败

java - Spring 无法 Autowiring 字段,没有匹配的类型的 bean

java - 如何在矩形的边框上画一个点?