I'm practicing for my java test on sunday and I did this lab and everything is okay except for the zero I don't know why the zero is there and I want to reverse the triangle form this :
0
10
210
3210
43210

to this
1
21
321
4321

and form
0
10
210
3210
43210
to
1
12
123
1234

and from
0
10
210
3210
43210
to
1234
123
12
1
and form
0
10
210
3210
43210
to
4321
432
43
4

and form
0
10
210
3210
43210
to
1
23
234


how can I do it ??
and this is my code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trianglenumber;

import java.util.Scanner;

public class TriangleNumber {

    static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        System.out.print("What is size of triangle ");
        int count = input.nextInt();
        for (int i = 0; i <= count; i++) {
            System.out.println(spaceLine(count + i) + numberLine(i) + "" + sum(i));
        }

    }

    public static String numberLine(int count) {
        String result = "";
        for (int i = count; i > 0; i--) {
            result = result + i;
        }
        return result;
    }

    public static String spaceLine(int count) {
        String result = "";
        for (int i = count; i > 0; i--) {
            result = result + "";
        }
        return result;
    }

    public static int sum(int count) {
        int result = 0;
        for (int i = 0; i > count; i++) {
            result = result + i;
        }
        return result;
    }
}

Have you an algorithm for outputing the numbers in the order that you want them to be printed? Is there one algorithm for all the output or is there a different one for each pair of outputs you have posted?
You have posted a lot of samples of program output but I'm not sure which they are.
Is the first one of each pair what your code currently does and the second one is what you want the program to do?

There is only one input from the user, how do you know how to create the triangle from that one input. Some triangles start with a single digits and add more digits on following rows.
Some triangles start with more than one digit and reduce the number of digits on each row.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.