I Need A Java Code That Will Help Me Output A Diamond Shape?

6

6 Answers

Tauseef Sheikh Profile
Tauseef Sheikh answered
The code is very simple. Try this

import java.io.*;

public class myDiamondInput {

public static void main(String [] args) throws IOException {

BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));

String input;
int num;


System.out.println("input number: ");
input = stdin.readLine ();
num = Integer.parseInt(input);

int d = num;
int e = 0;

for (int a = 0; a <= num; a++) {
for (int c = d; c>= 1; c-- )
System.out.print(" ");
d-=1;
for (int b = 1; b <= a; b++)
System.out.print ("* ");
System.out.println();
}
num-=1;

for (int a = 0; a<=num; a++) {
for (int b = num; b > a; b--)
System.out.print (" *");
System.out.println();
for (int c = 0; c <= e; c++)
System.out.print(" ");
e+=1;

}
}

}
Anonymous Profile
Anonymous answered
Import java.io.*;

    public class myDiamondInput {

  public static void main(String [] args) throws IOException {
 
  BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
 
  String input;
  int num;
 
 
  System.out.println("input number: ");
  input = stdin.readLine ();
  num = Integer.parseInt(input);
 
  int d = num;
  int e = 0;

  for (int a = 0; a = 1; c-- )
  System.out.print(" ");
  d-=1;
  for (int b = 1; b
Anonymous Profile
Anonymous answered
A java program that will output a number that shapes a diamond
Aya Hussein Profile
Aya Hussein answered
Class DiamondPattern
{
public static void main(String[] args)
{
System.out.println("Program for displaying pattern of *.");
System.out.print("Enter the maximum number of *: ");
int n = 6;
System.out.println("nHere is the Diamond of Starsn");
for (int I = 1; I

Answer Question

Anonymous