// 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(); } } } }
int longestRow = x;
for(int row=1; row<=longestRow;row++){ //places the symbols for the diamond
int i = (2*row) - 1;
if(i>longestRow) i = 2*(longestRow-row+1) - 1;
for(int column=0 ; column<(longestRow-i)/2 ;column++) System.out.print(" "); //creates the empty spaces for the diamond
for(int column=0 ; column<i ; column++) System.out.print(ch);
for(int column=0 ; column<(longestRow-i)/2 ; column++) System.out.print(" ");
System.out.println(); //prints the diamond
//first you have to define ch for the character you want to use, and also enter the number for the longest row and you should be set
You may exit a nested loop in Java using a break with a label for the outer loop.
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.
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 < n; i++) { ..... } while (i < n) { ... i++; } do { ... i++; } while (i < n) ;
Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.
You use loops in Java when you want a set of actions to be repeated until a particular condition is met or for a certain number of times.The different types of loops in Java are:For LoopsDo-While LoopsWhile Loops
You may exit a nested loop in Java using a break with a label for the outer loop.
for loop function
in a loop
1) use for loop 2) do while loop
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.
The do while loop is also called an exit condition loop in c, c++, and 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.
Exactly what do you mean by 'C program 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 < n; i++) { ..... } while (i < n) { ... i++; } do { ... i++; } while (i < n) ;
Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.
Yes it is possible to draw in java by using AWT package. or by using javax package.
write a program draw circle and ellipse by using oval methods in java