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 comes to mind when someone mentions a shallow copy in java?
What is the program compilation process?
explain me with a code snippet about the generation and handling of null point exceptions.
What is unicode full form?
What is struts in java?
public class Garbage { int a=0; public void add() { int c=10+20; System.out.println(c); System.out.println(a); } public static void main(String args[]) { Garbage obj=new Garbage(); System.gc(); System.out.println("Garbage Collected"); obj.add(); } } Above is a code in java used for garbage collection. object obj has been created for the class Garbage and system.gc method is called. Then using that object add method is called.System.gc method if called the obj should be garbage collected?
What is return type in java?
Why java is free from garbage values??
Hi can u pls tell me what is the use of marker interface. Iknow what is marker interface but what ability will the object get by implementing this.
What is thread pool? How can we create thread pool in java?
What is java autoboxing?
Can we have return statement in finally clause? What will happen?