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 9225389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:33:49+00:00 2026-06-18T04:33:49+00:00

I am working on a loan calculator with data validation. I have written everything

  • 0

I am working on a loan calculator with data validation. I have written everything and good to go. The only thing I cannot figure out is how to write a while loop in where the user is asked “Continue y/n?: ” and then have the program continue ONLY when the user types y/Y and the program ENDS ONLY when the user types n/N, any other input should give an error message like “Invalid, you can only enter Y or N”. So if the user enters “x” it should display the error message.

I have tried else if clauses, I have also tried to validate data with the methods I used in the rest of the program but I simply don’t know how to validate strings. I can only do it with primitive data types.

This is the only way i know how to write the loop as of now, the problem is it will simply end the program with anything but a Y.

an option for the assignment is to use JOptionPane but I do not know how to incorporate that into the while loop and have it display a yes and a no button.

    String choice = "y";

    while (choice.equalsIgnoreCase("y")) {

    // code here

    System.out.print("Continue? (y/n): ");
        choice = sc.next();
    }
   }
  • 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-18T04:33:51+00:00Added an answer on June 18, 2026 at 4:33 am

    Essentially, you want two loops: one doing the work and the other one inside prompting for user validation.

    boolean isContinuing = true;
    
    while (isContinuing) {
        // do work
    
        boolean inputIsInvalid = true;
        while (inputIsInvalid) {
          System.out.print("Continue? (y/n): ");
    
          String choice = sc.next();
    
          if ("y".equalsIgnoreCase(choice)) {
              inputIsInvalid = false;
          }
          else if ("n".equalsIgnoreCase(choice)) {
              inputIsInvalid = false;
              isContinuing = false;
          }
          else {
              System.err.print("Error: Only valid answers are Y/N.");
          }
        }
    }
    

    Node: I am using boolean variables instead of break statements, it makes the code more straightfoward and readable.

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

Sidebar

Related Questions

Working on a project using Entity Framework (4.3.1.0). I'm trying to figure out how
Working on some check-in functionality for an application, and trying to figure out the
I am writing a Mortgage Calculator for class and I have it working the
i am working on a simple loan calculator, so simple that it's not even
I am working on an eshop with a calculator to calculate your loan. I
Working in VS2010 / C# - I have a form that shows data by
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working with H2 I get this error when I try to write a row
I am working on an e-shop which sells products only via loans. I display
I am working on the front end of an application. I have to introduce

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.