how to print the below in java?thanks in advance....
*
* *
* *
* *
*

Answers were Sorted based on User's Feedback



how to print the below in java?thanks in advance.... * * ..

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

how to print the below in java?thanks in advance.... * * ..

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

how to print the below in java?thanks in advance.... * * ..

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

Post New Answer

More Core Java Interview Questions

What comes to mind when someone mentions a shallow copy in java?

0 Answers  


What is the program compilation process?

0 Answers  


explain me with a code snippet about the generation and handling of null point exceptions.

1 Answers  


What is unicode full form?

0 Answers  


What is struts in java?

0 Answers  






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?

6 Answers  


What is return type in java?

0 Answers  


Why java is free from garbage values??

4 Answers  


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.

3 Answers   CGI,


What is thread pool? How can we create thread pool in java?

0 Answers  


What is java autoboxing?

0 Answers  


Can we have return statement in finally clause? What will happen?

0 Answers  


Categories