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
FILE PROGRAMMING
Why do we use int main?
Simplify the program segment if X = B then C ← true else C ← false
What are the 4 types of organizational structures?
How do you write a program which produces its own source code as output?
What is chain pointer in c?
What are header files in c programming?
Difference between Function to pointer and pointer to function
Is c object oriented?
Is sizeof a keyword in c?
Describe dynamic data structure in c programming language?
Is that possible to store 32768 in an int data type variable?
When is a null pointer used?
can any one provide me the notes of data structure for ignou cs-62 paper
Explain the difference between ++u and u++?