#confused

48 messages · Page 1 of 1 (latest)

wanton delta
#

so its giving me an error i am not understanding

sacred agateBOT
#

Hey, @wanton delta!
Please remember to /close this post once your question has been answered!

wanton delta
#
{
  public static void main(String[] args)
  {
    String test1 = "WOW";
    String test2 = "BEN";
    String test3 = "SAMMY";
    String test4 = "WILE";
    String test5 = "APLUSCOMPSCI";

    System.out.println(printTriangle(test1));
    System.out.println(printTriangle(test2));
    System.out.println(printTriangle(test3));
    System.out.println(printTriangle(test4));
    System.out.println(printTriangle(test5));

    public static int printTriangle(String input) {
        String tmp = input.substring(1);
        StringBuilder builder = new StringBuilder(tmp);
        builder = builder.reverse().append(input);
        String line = builder.toString();
        for(int i = 0; i < input.length(); i++){
            for(int j = 0; j < line.length(); j++){
                
                if(i + 1 == input.length() || Math.abs(j - line.length()/2) == i){
                    System.out.print(line.charAt(j));
                }else{
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
  }```
devout gorge
#

You put the printTriangle method in the main method

wanton delta
#

giving same error

devout gorge
#

If you take it out it gives same error?

wanton delta
#

my bad i messed up

#

but now its giving me a error that says "cannot find symbol" pointing at the printtriangle in the main file

devout gorge
#

I think you put out of the class as well

#

Or you misspelled something

#

Lemme see the new code

#

Preferably a picture

#

So I don't have to keep track of curly braces

wanton delta
devout gorge
#

Oh

#

The print triangle is in another class

#

So do TriangleWord.printTriangle();

#

@wanton delta

wanton delta
#

yeah i think it works its jsut giving me a bug saying im missing a return statement even though its there

devout gorge
#

Its not

wanton delta
#

on ln23

#

of Triangle word

devout gorge
#

Line 23 is {

#

It's just a curly brace

wanton delta
#

yeah i know its there and its still giving me the error

devout gorge
#

You didn't add a return value

#

That's why

#

System.out.println() and return are not the same

#

You have to add a return statement

#

In printTriangle

#

@wanton delta

wanton delta
#

what do i return

devout gorge
#

Idk

#

You should know

#

Otherwise change the int to void

#

If you don't want to return something

wanton delta
#

i would but it would give me the error "void typr not allowed here"

devout gorge
#

That's odd

#

Just change it to void either way

#

and then in the main class

#

Get rid of the System.out.println()

#

Just change them to printTriangle()

#

Since it doesn't return anything

#

@wanton delta

wanton delta
#

i got it

#

Thank you