Home TechnologyProgrammingJava Subscribe to RSS
 

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

I am trying to write a Program that will Accept an integer between 5 and 10 and use the value as the number of rows to print out all 3 figures below. Could someone help me with this problem please. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Answer Question

2 Answers - Sort by: Date | Rating

    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;
                    
                }
            }
            
        }
    0 0

    Tausif 

    answered 2 years ago

      A java program that will output a number that shapes a diamond
      0 0
      Guest

      Guest 

      answered 3 months ago

        Answer Question - Answers are editable for 5 min.

        If you do not Sign-in or Register your answers will be anonymous,

        your answers may also be checked before going online.

        More

           
           

          Ask a Question via Twitter

          Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

          Blurtit Store

          Get T-shirts, hoodies, caps and more at the Blurtit store

          Blurtit International