Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8818247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:03:56+00:00 2026-06-14T05:03:56+00:00

Can someone explain why? I always encounter an infinite loop when I use a

  • 0

Can someone explain why? I always encounter an infinite loop when I use a do-while loop. What am I missing?

package com.assignment2;

public class FooCorporation {

    public static void main(String[] args) {

        employee(9.50, 55);
        employee(8.20, 47);
        employee(10.00, 73);

    }

    public static void employee(double basePay, int hoursWorked) {

        double salary = 0;
        int overtimeHours = 40;

        do {
            if (basePay >= 8.00 || hoursWorked > 40 ) {
                if (hoursWorked > 40) {
                    salary = basePay * hoursWorked
                            * ((hoursWorked - overtimeHours) * 1.5);
                } else {
                    salary = basePay * hoursWorked;
                }

            }

            else 
                System.out.println("According to law: Base Pay should be more than $8.00");

            System.out.printf("Total Pay: %d %.2f\n", hoursWorked, salary);

        } while (hoursWorked <= 60);

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:03:57+00:00Added an answer on June 14, 2026 at 5:03 am

    You’re never modifying hoursWorked‘s value so the condition is always met, hence the infinite loop. You’ll want to increment it’s value at the end of each iteration, after

        else 
            System.out.println("According to law: Base Pay should be more than $8.00");
    
        System.out.printf("Total Pay: %d %.2f\n", hoursWorked, salary);
    
        //Right here
    } while (hoursWorked <= 60);
    

    Edit Just as an extra mile, I’m not getting the meaning of that loop. When would you increase hoursWorked‘s value? Shouldn’t that be something related to a particular employee? Seems like if you wanted to do that for every employe who worked 60 hours or less. In that case you should have a list of Employee objects and iterate over them, picking up only the eployees who worked the amount of hours you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I develop a dnn module and use public class classNameInfo: IHydratable (c#) Can someone
Can someone explain why it's best use is for prototyping? Should it not be
Can someone explain why examples on threading will always make an object (specifically a
Can someone explain that why do arithmetic operations on integral types in Java always
Can someone explain this one to me: http://jsperf.com/string-concatenation-1/2 If you're lazy, I tested A)
Can someone explain to me why this is always always getting only one color
Can someone explain to me use of Me.prototype.constructor = Me; and why is needed,
I see them all the time and always ignore them. Can someone explain to
Can someone explain me why this code give me back always only one bluetooth
Can someone explain this simple, yet deceiving, anomaly? There are two models, where B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.