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

  • Home
  • SEARCH
  • 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 3312080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:57:08+00:00 2026-05-17T21:57:08+00:00

I want to do some calculations with polygons. So I need the user to

  • 0

I want to do some calculations with polygons. So I need the user to input some x and y coordinates. This is performed by the following code:

private static boolean isX = true;
private static Scanner scanner = new Scanner(System.in);

private static double readDouble() {
    double value = 0;
    System.out.print("Koordinate " + (isX ? "X" : "Y") + " : ");
    value = scanner.nextDouble();
    if (!isX)
        System.out.println("--------------------");
    isX = !isX;
    return value;
}

To calculate the outline of a polygon I need the total amount of polygons. The input is performed in a loop. The input should end when the the last polygon data has the same coordinates as the first. E.g. first input would be X: 1 Y:1, X: 1, X: 2 would end the input.

    double fX = readDouble(); double x = 0.0;
    double fY = readDouble(); double y = 0.0;

    int nVertex = 1;

    while((x != fX) && (y != fY)){
        nVertex++;
        x = readDouble(); y = readDouble();
    }

But the input in the loop is perfomed only ones. So something is wrong with the break condition.

any ideas?

  • 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-17T21:57:08+00:00Added an answer on May 17, 2026 at 9:57 pm

    You should have or (||), not and (&&)

       while((x != fX) || (y != fY)){
            nVertex++;
            x = readDouble(); y = readDouble();
        }
    

    You want to contine as long as x is not equal to fX or y is not equal to fY -that is

    NOT (x == fX AND y == fY)
    

    in pseudo code. With your current code, you’ll terminate the loop as soon as one of x and y are the same as the initial values.

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

Sidebar

Related Questions

I have some very heavy code to develop and want to make some calculations
I have an Excel-based application that gathers some user input, and makes some calculations
I'm having the following problem in python. I need to do some calculations in
I need to do some calculations based off shipping options. For this example I
I'm attempting to do some calculations for a running total, this is my code:
Say I want to have a simple web app that takes some user input,
I want some code to be triggered every second. Usually, I'd create a Timer
I want some like this: How make it ideologically correct?
I want some static pages of application to be rendered from XML i.e. i
I have a huge line-separated text file and I want to make some calculations

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.