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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:44:16+00:00 2026-05-23T03:44:16+00:00

This is the Pseudocode I have written for a JAVA application to calculate distance

  • 0

This is the Pseudocode I have written for a JAVA application to calculate distance using coordinates.

totalDistance (int[] x, int[] y, int i)
    If x = 1 then
        distance =  pow(x[i] – x[i – 1], 2) + pow(y[i] – y[i – 1], 2)
        return  round(sqrt(distance))
    else
        return round(sqrt(distance)) + totalDistance(x, y, i – 1)

I am not really great with Java, but I wrote the below out. When I pass variables to it it crashes.

import java.util.Scanner;



class distance {

    public static void main(String[] args) {
        System.out.println("Welcome to Travel Bliss Distance Calculator!");
        Scanner input = new Scanner(System.in);
        int[] x = new int[5];
        int[] y = new int[5];
        String[] city = new String[5];

        int i=0;
        for (i=0; i < 5;){

            System.out.println("Enter X Coordinates>>");
            x[i] = input.nextInt();
            System.out.println("Enter Y Coordinates>>");
            y[i] = input.nextInt();
            System.out.println("With Coordinates: (" + x[i] + "," + y[i] + ") ");
            i++;
        }
        totalDistance(x, y, i);
    }


    public static double totalDistance(int[] x, int[] y, int i){
        double distance;
        if (i == 1){
               distance = pow(x[i] – x[i – 1], 2) + pow(y[i] – y[i – 1], 2);
               return distance;
            }
            else {
                return round(sqrt(distance)) + totalDistance(x,y,i-1);
            }
    }


}

Anyone know what I am doing wrong?? Or why I am getting a crash

This is ERROR>>

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Syntax error on token "[", Expression expected after this token
    distance cannot be resolved to a variable
    The type of the expression must be an array type but it resolved to int
    Syntax error on token "Invalid Character", [ expected
    The type of the expression must be an array type but it resolved to int
    Syntax error on token "Invalid Character", [ expected
    Syntax error, insert "]" to complete ArrayAccess
    Syntax error, insert "]" to complete ArgumentList
    The type of the expression must be an array type but it resolved to int
    Syntax error on token "Invalid Character", [ expected
    The type of the expression must be an array type but it resolved to int
    Syntax error on token "Invalid Character", [ expected
    Syntax error, insert "]" to complete ArrayAccess
    Syntax error, insert "]" to complete ArgumentList
    distance cannot be resolved to a variable
    Syntax error on token "Invalid Character", invalid AssignmentOperator

    at distance.totalDistance(distance.java:30)
    at distance.main(distance.java:24)
  • 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-23T03:44:16+00:00Added an answer on May 23, 2026 at 3:44 am
    public static double totalDistance(int[] x, int[] y, int i){
             int distance = pow(x[i] – x[i – 1], 2) + pow(y[i] – y[i – 1], 2);
            if (x.length == 1){
               return distance;
            }
            else {
                return round(sqrt(distance)) + totalDistance(x,y,i-1);
            }
    }
    

    You need to declare the return type to double instead of void.
    You meed to declare the variable distance outside of the if statement.
    An array will never equal an integer, I assume you’re going after its size.

    There are still some mistakes with your logic here, but I don’t want to do all of your homework for you.

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

Sidebar

Related Questions

I am using pseudo-code here, but this is in JavaScript. With the most efficient
NOTE: This question is written in a C# like pseudo code, but I am
I have written 2 implementation of bubble sort algorithm in C and Haskell. Haskell
To solve a problem (and better my understanding of multitasking) I have written a
I'm wondering if this is possible. I have html like so: <p> <font face=Georgia>
I'm trying to implement HMAC-SHA1 algorithm in my C++/Qt application. I have a method
I have found this example on StackOverflow: var people = new List<Person> { new
Ok below is the full code I have written for what is suppose to
I have the following Haskell code import Data.Int import System.Environment type Coord = (Int16,
This is a bit of a long shot, but if anyone can figure it

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.