answersLogoWhite

0

// Import Library

import javax.swing.*;

//Beginning class Diamond

public class Diamond

{

//Main method

public static voidmain(String[] args)

{

//Declaring Variables

String strRow = null;

double dblRow = 0;

//GUI user input

strRow = JOptionPane.showInputDialog("Please enter an ODD number ");

dblRow = Integer.parseInt(strRow);

//validate a odd number

if ((dblRow % 2)== 0)

//if not an odd number user is advised

JOptionPane.showMessageDialog(null, "The number entered is not an ODD number. Please, try again");

//Building diamond

else

{

//setting up first 1/2 of the diamond - rows

for(int a=1; a<(dblRow/2+.5); a++ )

{

//Assigning empty spaces from right side

for (int b=1; b<(dblRow/2+1.5)-a; b++)

{

System.out.print(" ");

}

//filling out with *

for(int c=0; c<(a*2)-1; c++)

System.out.print("*");

System.out.println();

}

//Creating middle line of the diamond

for(int d=1; d

{

System.out.print("=");

}

System.out.println();

//setting our second 1/2 of the diamond - rows

for(int a=1; a<(dblRow/2+.5); a++ )

{

//Assigning empty spaces from right side in second part of diamond

for(int c=0;c

System.out.print(" ");

//filling out with *

for(int b=1; b

{

System.out.print("*");

}

System.out.println();

}

}

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

How do you exit in nested loop in java?

You may exit a nested loop in Java using a break with a label for the outer loop.


What are functions in JAVA?

for loop function


How can you use the "break" statement in Java to prematurely exit a "for" loop?

In Java, you can use the &quot;break&quot; statement within a &quot;for&quot; loop to exit the loop prematurely. When the &quot;break&quot; statement is encountered, the loop will immediately stop executing and the program will continue with the code after the loop.


When is Iteration used in a Java program?

in a loop


How can you repeatedly execute a code in java script?

1) use for loop 2) do while loop


Which Loop avoids check at every iteration?

All loops available in Java (for, while, do-while) have a loop termination condition that would get executed during every iteration of the loop. Without checking the loop condition the loop cannot be terminated and hence avoiding the loop condition check during iteration is not logic and Java does not do it.


Which loop is also called an exit-condition loop in C programming?

The do while loop is also called an exit condition loop in c, c++, and java.


What is a nested loop in java?

A nested loop is a (inner) loop that appears in the loop body of another (outer) loop. The inner or outer loop can be any type: while, do while, or for. For example, the inner loop can be a while loop while an outer loop can be a for loop.


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


What are various loops available in java?

Java has three kinds of loops 1. For Loop 2. While Loop 3. Do - While Loop Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied. A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once. Example Declarations: for(int i = 0; i &lt; n; i++) { ..... } while (i &lt; n) { ... i++; } do { ... i++; } while (i &lt; n) ;


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


Write a java code to draw a circle inside in an ellipse?

write a program draw circle and ellipse by using oval methods in java