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
What is the difference between the local variable and global variable in c?
swap 2 numbers without using third variable?
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
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
How do you determine whether to use a stream function or a low-level function?
What is the advantage of an array over individual variables?
What is difference between %d and %i in c?
Define and explain about ! Operator?
How can I automatically locate a programs configuration files in the same directory as the executable?
What does d mean?
Explain union.
Explain how do you determine the length of a string value that was stored in a variable?
What is indirection? How many levels of pointers can you have?
Explain what are global variables and explain how do you declare them?
How can I manipulate individual bits?