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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:50:26+00:00 2026-06-15T01:50:26+00:00

Here’s my code as it stands: import static java.lang.System.*; public class Triples { private

  • 0

Here’s my code as it stands:

import static java.lang.System.*;

public class Triples
{
 private int number;

public Triples()
{
    this(0);
}

public Triples(int num)
{
    number = num;
}

public void setNum(int num)
{
    number = num;
}

private int greatestCommonFactor(int a, int b, int c)
{
    for(int n = 0; n <= number; n++)
    {
    int max = number;
    for(a = 1; a <= max; a++)
    {
        a = n;
        for(b = a +1; b <= max; b++)
        {
            b =n;
            for(c = b + 1; c <= max; c++)
            {
                c = n;
                if(Math.pow(a, 2)+ Math.pow(b, 2)== Math.pow(c, 2))
                {
                    if((a%2==1 && b%2==0)|| (a%2==0 && b%2==1))
                    {
                        if(a%2<=1 && b%2<=1 && c%2<=1)
                        {
                            return 1;
                        }
                    }
                }
            }
        }
    }
    }

    return 1;
}

public String toString()
{
    String output="";
    output = greatestCommonFactor(a, b, c);


    return output+"\n";
}
}

I need to have it print out the variables a, b, and c but I can not figure out how to make it do so. The error message I’m currently receiving is “a cannot be resolved to a variable
b cannot be resolved to a variable
c cannot be resolved to a variable”

here’s a link to the associated labsheet if it helps: https://docs.google.com/open?id=0B_ifaCiEZgtcX08tbW1jNThZZmM

UPDATE
here’s my updated toString method:

public String toString()
{
    int a = 0;
    int b = 0;
    int c = 0;
    String output="";
    output += greatestCommonFactor(a, b , c) + "\n";


    return output;
}

and while I’m editing, my greatestCommonFactor method:

private int greatestCommonFactor(int a, int b, int c)
{
    for(int n = 0; n <= number; n++)
    {
    int max = number;
    for(a = 1; a <= max; a++)
    {
        a = n;
        for(b = a +1; b <= max; b++)
        {
            b =n;
            for(c = b + 1; c <= max; c++)
            {
                c = n;
                if(Math.pow(a, 2)+ Math.pow(b, 2)== Math.pow(c, 2))
                {
                    if((a%2==1 && b%2==0)|| (a%2==0 && b%2==1))
                    {
                        if(a%2<=1 && b%2<=1 && c%2<=1)
                        {
                            return greatestCommonFactor(a, b, c);
                        }
                    }
                }
            }
        }
    }
    }

    //return 1;
}

UPDATE #2

Here’s (hopefully) a more correct way of writing the code for the greatestCommonFactor and toString methods:

private int greatestCommonFactor(int a, int b, int c)
{
    a = 0;
    b = 0;
    c = 0;
    for(int n = 0; n <= number; n++)
    {
    int max = number;
    for(a = 1; a <= max; a++)
    {
        a = n;
        for(b = a +1; b <= max; b++)
        {
            b =n;
            for(c = b + 1; c <= max; c++)
            {
                c = n;
                if(Math.pow(a, 2)+ Math.pow(b, 2)== Math.pow(c, 2))
                {
                    if((a%2==1 && b%2==0)|| (a%2==0 && b%2==1))
                    {
                        if(a%2<=1 && b%2<=1 && c%2<=1)
                        {
                            return a;
                        }
                    }
                }
            }
        }
    }
    }

    return greatestCommonFactor(a, b, c);
}

public String toString()
{

    String output="";
    output += greatestCommonFactor(a, b , c) + "\n";


    return output;
}

Runner Class addition

import static java.lang.System.*;

import java.util.Scanner;

public class Lab11j
{
 public static void main(String args[])
 {
       Scanner keyboard = new Scanner(System.in);
        String choice="";
            do{
                out.print("Enter the max number to use : ");
                int big = keyboard.nextInt();


                    //instantiate a TriangleThree object
             Triples trip = new Triples( big);
                //call the toString method to print the triangle
                System.out.println( trip );

                System.out.print("Do you want to enter more data? ");
                choice=keyboard.next();
            }while(choice.equals("Y")||choice.equals("y"));
    }
}
  • 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-15T01:50:30+00:00Added an answer on June 15, 2026 at 1:50 am

    You’re using variables without declaring and initializing them:

    output = greatestCommonFactor(a, b, c); // where are a, b and c decleared in this method?
    

    Moreover, your greatestCommonFactor() method takes arguments, but does nothing else than reinitializing them, so it could very well not take any argument at all:

    private int greatestCommonFactor(int a, int b, int c) {
        for (int n = 0; n <= number; n++) {
            int max = number;
            for (a = 1; a <= max; a++)
            // here you're setting a to 1. So why pass its value as an argument to the method,
            // since you don't care about the passed in value? 
    

    EDIT:

    instead of having

    private int greatestCommonFactor(int a, int b, int c) { // these are arguments
        a = 0;
        b = 0;
        c = 0;
        ...
    }
    

    you should have

    private int greatestCommonFactor() {
        int a = 0;
        int b = 0;
        int c = 0; // these are local variables
        ...
    }
    

    Instead of having

    public String toString() {
        String output="";
        output += greatestCommonFactor(a, b , c) + "\n";
        return output;
    }
    

    you should have

    // yes, this method name is ugly, but it says what the method does
    // I would simply make greatestCommonFactor a public method, and remove this method,
    // since it doesn't do anything useful.
    public String computeGreatestCommonFactorAndReturnItAsAStringWithANewLine() {
        return greatestCommonFactor() + "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
here is my code, SiteMember class @OneToMany(mappedBy = member,cascade=CascadeType.ALL) private List<MemberThread> memberThread = new
Here's my class: public class JsoupParser { ArrayList<CompanyInfo> arr = new ArrayList<CompanyInfo>(); public static
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my function: static Map AddFormation(Map _map, Tile tile, int x, int y, int
Here is a code snippet I was working with: int *a; int p =
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`

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.