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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:25:43+00:00 2026-05-17T22:25:43+00:00

This is my situation: i need the code to run in a loop, over

  • 0

This is my situation:

i need the code to run in a loop, over and over again asking the same question(s) to the user, until the user types a “q” for any point to terminate/exit the loop, thus exiting the program.

The problem is that i tried to used a do-while/while loop, and those loops executes only if the conditions comes out to be true. But i need the condition (“q”) to be false so it can continue the loop. If the condition is true (input.equals(“q”)) , then it just does not nothing because instead of the integer/double, it will use a string (“q”) to calculate the distance.

i have already figured out how to get the distance, the code as is works well, but is there any work-around that i can make the loop continue while the condition is false?

and by the way, i am just barely learning java just in case…

‘.

import java.*;
public class Points {
public static void main(String[] args){

    java.util.Scanner input = new java.util.Scanner(System.in);

    System.out.print("Enter the first X coordinate: ");
    double x1 = input.nextDouble();
    System.out.print("Enter the first Y coordinate: ");
    double y1 = input.nextDouble();
    System.out.print("Enter the second X coordinate: ");
    double x2 = input.nextDouble();
    System.out.print("Enter the second Y coordinate: ");
    double y2 = input.nextDouble();
    System.out.println("(" + x1 + ", " + y1  + ")" + " " + "(" + x2 + ", " + y2+ ")");

    double getSolution = Math.sqrt(((x2-x1) * (x2-x1)) + ((y2-y1) * (y2-y1)));
    System.out.println(getSolution);
    }
}'
  • 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-05-17T22:25:44+00:00Added an answer on May 17, 2026 at 10:25 pm

    The solution to this is to use String line = input.nextLine() instead of nextDouble(). Then you can have a method like:

    public static boolean timeToExit(String input) {
        return input.equalsIgnoreCase("q");
    }
    

    This method will need to be called each time the user provides input:

    if (timeToExit(line)) break;
    

    That will exit a loop.

    Now, since you have a String representation of the double, you will need to use Double.parseDouble(line) to turn the String into a number.

    Then all you have to do is enclose everything in an infinite loop -> while(true) { }

    And, the only time it will exit the loop is if the timeToExit method returned true, and you break the loop.

    This all turns into something like:

    while (true) {
        ...
        System.out.print("Enter the first X coordinate: ");
        String x1 = input.nextLine();
        if (timeToExit(x1)) break;
        double x1_d = Double.parseDouble(x1);
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in this situation that i need a list of lists. for instance i
this is the situation: I need horizontal scrolling, and table views inside every page.
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
Using this file as source, I have a situation where I need to retrieve
I'm wondering what is the culturally-acceptable way to handle this code situation. I have
This sort of situation comes up pretty often. You loop through an array, and
I mean preventing any action closing-unloading-terminating they all should be prevented until the code
This code does not run properly, but it suggests what I am trying to
How to set the same name for parent and child in this situation? public
My apologies if this is just another question that gets asked over and over.

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.