how to print the below in java?thanks in advance....
*
* *
* *
* *
*
Answers were Sorted based on User's Feedback
Answer / keerthi
public class Diamond{
public static void main(String args[]){
int n=10;
int m=n/2;
int p=0;
for(int i=0; i<=n;i++){
if(i>m)
p++;
for(int j=0; j<=n;j++){
if((m-i)==j ||(m+i)==j || (i-j)==m ||(i>m && (n-p)==j))
System.out.print("*");
else
System.out.print(" ");
}
System.out.println("\n");
}//First for loop end
}//Main
}//Class end
output:
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / venkat
In the above program 4th line from last remove "\n"
ie. shoule be System.out.println("")
below is output:
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / jitendra
for(i=1;i<=3;i++)
{
for(j=3;j>=i;j--)
System.out.printf(" ");
System.out.printf("*");
for(j=1;j<2+i;j++)
System.out.printf(" ");
System.out.printf("*");
System.out.printf("\n");
}
this is to print
*
* *
* *
now apply ur brain to print the rest...
any problem ..then mail me
jitendrasharma13@gmail.com
| Is This Answer Correct ? | 2 Yes | 6 No |
What is a buffer in java?
What one should take care of, while serializing the object?
Write a function to find out longest palindrome in a given string?
Difference between nested and inner classes ?
Is main is a keyword?
What is multi level inheritance in java?
What are the limitations of procedural programming approach?
Is multiple inheritance allowed in Java? Why ?
Explain the usage of this with constructors?
There is a Banking application. It has 2 types of account, Savings and Current. Write a method calculateInterest by passing an ArrayList of these account objects and calculate Interest accordingly. Write code for this situation
1) There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?
When is update method called?