简体   繁体   中英

while loop do not loop

Hi i am practicing java and just learning java for few days. i need to subtract the scholarship amount of 500000 by 100000 but i seemed to be stuck on 400000 and it does not continue. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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