write a program to display the numbers in the following
format
4 4
3 3 3 3
2 2 2 2 2 2
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1
2 2 2 2 2
3 3 3
4

Answer Posted / meet parikh

public class Arrow_1 {
private final int LARG = 4;
String printint,fillint;
boolean display = false;
public Arrow_1(){
fillint = " ";
for(int i = LARG; i >= 0; i--){
if(i == 0){
display = true;
fillint = 0 + "";
}
StringBuilder sb = new StringBuilder();
printint = i + "";
insertDisp(sb, i);
System.out.println(sb.toString());
}
printint = " ";
for(int i = LARG; i>0;i--){
StringBuilder sb = new StringBuilder();
fillint = LARG - (i-1) + "";
insertDisp(sb,i);
System.out.println(sb.toString());
}
}
private void insertDisp(StringBuilder sb,int number){
printDisp(sb, number);
fillempty(sb, number);
if(display){
sb.append(fillint);
} else {
sb.append(" ");
}
fillempty(sb, number);
printDisp(sb, number);
}
private void printDisp(StringBuilder sb,int number){
int itr;
if(number == 0){
itr = LARG;
} else {
itr = LARG - (number-1);
}
for(int i = 0 ; i < itr;i++){
sb.append(printint);
}
}
private void fillempty(StringBuilder sb, int number){
for(int i = 0; i < number-1 ;i++ ){
sb.append(fillint);
}
}
public static void main(String args[]){
new Arrow_1();
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between the local variable and global variable in c?

520


swap 2 numbers without using third variable?

650


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

1723


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

2708


How do you determine whether to use a stream function or a low-level function?

631






What is the advantage of an array over individual variables?

721


What is difference between %d and %i in c?

678


Define and explain about ! Operator?

603


How can I automatically locate a programs configuration files in the same directory as the executable?

614


What does d mean?

568


Explain union.

627


Explain how do you determine the length of a string value that was stored in a variable?

655


What is indirection? How many levels of pointers can you have?

648


Explain what are global variables and explain how do you declare them?

624


How can I manipulate individual bits?

594