Q:

Java Program to display the pattern like a diamond

0

Program to display the pattern like a diamond of stars with getting the input from the user using java language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class demo1 
{
  public static void main(String[] args)	 	  
     {
        int i,j,r;
        System.out.print("Input number of rows (half of the diamond) : ");
        Scanner input = new Scanner(System.in);
		    r = input.nextInt();
        for(i=0;i<=r;i++)
          {
            for(j=1;j<=r-i;j++)
            System.out.print(" ");
            for(j=1;j<=2*i-1;j++)
            System.out.print("*");
            System.out.print("\n");
          }
        for(i=r-1;i>=1;i--)
          {
            for(j=1;j<=r-i;j++)
            System.out.print(" ");
            for(j=1;j<=2*i-1;j++)
            System.out.print("*");
            System.out.print("\n");
          }
 
     }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now