Tutorial IV: Operators 5.20 Write an application that prints the following diamond figure. The following code is for the figure of a diamond in java.
import
javax.swing.JOptionPane; public class Diamond {public static void
main (String [] args) {int line, width, number, start, end, count, number = Integer
. parseInt (JOptionPane.showInputDialog ("Enter a number"));
width = (number * 2) - 1; start = width - number + 1;
for (counter = 1; counter System.out. print ("");
System.out.println ("*"); start -; end = start;
for (line = 2; line
{for (counter = 1; counter System.out.print (""); for (counter = start; counter
{System.out.println ("*");} System.out.println
("*"); Home - ;
end + +;} start = 1;
end = width - 1; for (counter = start; counter
{System.out.println ("*");}
System.out.println
("*"); start + +; end -= 2;
for (line = number + 1; line {for (counter = 1; counter System.out.print ("");
for ( counter = start; {counter
System.out.print ("*");} System.out.println
("*"); start + +; end -;}
start = width - number + 1; for (counter = 1; counter System.out.print (""); ("*"); System.out.println}}
0 comments:
Post a Comment