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
space 1
space23
space234
how can I do it ??
note: I can only for loop
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;
}
}