简体   繁体   English

while循环不循环

[英]while loop do not loop

Hi i am practicing java and just learning java for few days. 嗨,我正在练习Java,只是学习Java几天。 i need to subtract the scholarship amount of 500000 by 100000 but i seemed to be stuck on 400000 and it does not continue. 我需要将500000的奖学金金额减去100000,但是我似乎被困在400000上,而且这种情况不会持续下去。 What is wrong with my code please someone help me. 我的代码有什么问题,请有人帮我。 Thanks in advance. 提前致谢。

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);
      }
   }
}

You are never changing the scholarshipAmount amount 您永远不会改变scholarshipAmount金额

You need to do this 你需要这样做

 scholarshipAmount = scholarshipAmount - scholarship;

and you will then need to change this 然后您需要更改此

System.out.println(amount);

to

System.out.println(scholarshipAmount );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM