I wanna print the following shape
1
121
12321
1234321
12321
121
1
121
12321
1234321
12321
121
1
and I use the following code,put there are alot of errors
I want to know how i use the method toString to correct these errors
Expand|Select|Wrap|Line Numbers
- class Diamond {
- // main method begins execution of Java application
- public static void main( String args[] )
- {
- for(int x=0 ; x<=3 ; x++)
- {
- System.out.print(numbers(x));
- numbers(x);
- String r=numbers(x);
- String reversedString=reverse(r);
- System.out.print(reversedString);
- System.out.print("\n");
- if(x==3)
- for(x=x-1; x!=1 ; x--)
- {
- String y=numbers(x);
- y.toString();
- System.out.print(y);
- numbers(x);
- String r=numbers(x);
- String reversedString=reverse(r);
- System.out.prin(reversedString);
- System.out.print("\n");
- }
- }
- }
- String numbers (int x)
- {
- String p="";
- int n=1;
- int k=1;
- for( ; k<n+x ; k++)
- p+=k;
- System.out.print(n+x) ;
- return p;
- }
- }