Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an example of a keyword?

1015


What do you mean by ternary operator in java?

964


When should we create our own custom exception classes?

962


What is the biggest integer?

1001


What are the benefits of operations in java?

946


What is internal variable?

967


How does hashset work in java?

1062


In a container there are 5 components. I want to display all the component names, how will you do that?

2139


Can a source file contain more than one class declaration?

914


Explain exception chaining in java?

1089


How many types of string data types are there?

1021


what is an objects lock and which objects have locks? : Java thread

947


what is object-oriented programming in java?

1000


Are floats faster than doubles?

987


What is the default value of local and global variables?

1043