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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:09:43+00:00 2026-06-14T20:09:43+00:00

I have my code for this task mostly done, just can’t figure out what

  • 0

I have my code for this task mostly done, just can’t figure out what is causing the the output to be incorrect. The desired output when using say, 3 and A for the values, should return this:

A

AA

AAA

currently, I’m getting:

AAA

AAA

AAA

code:

import static java.lang.System.*;

public class TriangleThree
{
private int size;
private String letter;

public TriangleThree()
{
}

public TriangleThree(int count, String let)
{
    size = count;
    letter = let;
}

public void setTriangle( String let, int sz )
{
    size = sz;
    letter = let;
}

public String getLetter()
{
    return letter;
}

public String toString()
{
    String output="";
    for(int i = 1; i<=size; i++)
    {
        for(int j = 0; j > i;j++ )
        {
            output = output + " ";
        }
        
        for(int k = size; k>0; k--)
        {
            output = output + letter;
        }
        output= output + "\n";
    }
        
    
    
    
    
    return output+"\n";
}
}

and for cross-referencing it with my runner class:

import static java.lang.System.*;

import java.util.Scanner;

public class Lab11c
{
public static void main( String args[] )
{
   Scanner keyboard = new Scanner(System.in);
    String choice="";
        do{
            out.print("Enter the size of the triangle : ");
            int big = keyboard.nextInt();
            out.print("Enter a letter : ");
            String value = keyboard.next();

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

            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-14T20:09:44+00:00Added an answer on June 14, 2026 at 8:09 pm

    You are running your 2nd for loop 3 times (All from size to 0). Change it to: –

        for(int k = i; k>0; k--)
        {
            output = output + letter;
        }
    

    This will run 1 time for i = 1, 2 times for i = 2, …

    Also, there is a problem with your first loop: –

    for(int j = 0; j > i;j++ )
    

    this should really be: –

    for(int j = 0; j < i;j++ )
    

    UPDATE : –

    Actually you don’t need your first loop, as it is just printing spaces. Rather add spaces to your output in the 2nd loop only: –

        for(int k = i; k>0; k--)
        {
            output = output + letter + " ";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JS Fiddle (code) This is more of a task I have set myself to
I have this code in linux kernel: #define task_cred_xxx(task, xxx) ({ __typeof__(((struct cred *)NULL)->xxx)
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have code like this - (IBAction)onClick:(id)sender { NSThread *thread = [[NSThread alloc]initWithTarget:parser selector:@selector(adapter:)
I have code like this var MyObj = { f1 : function(o){ o.onmousedown =
I have code like this: ... entry.KeyPressEvent += EntryKeyPressEvent; ... } void EntryKeyPressEvent(object o,
I have code like this: string uriString = @C:\Temp\test.html; Uri uri = new Uri(uriString);
I have code like this: MediaElement me = myPlayer.MediaElement; WriteableBitmap wb = new WriteableBitmap(me.NaturalVideoWidth,
I have code like this (simplified): def outer(): ctr = 0 def inner(): ctr
I have code like this: <ul> <?php foreach($persons as $key) : ?> <?php if($this->session->userdata('id_user')

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.