Solid Rectangle Pattern | Write a program in Java to print a solid rectangle | ISC Computer Science | ICSE Computer Application.

Solid Rectangle

Algorithm

  1.   Start
  2. rows:=0
  3. columns:=0
  4. Print "Enter the number of rows: "
  5. Read rows
  6. Print "Enter the number of columns: "
  7. Read columns
  8. n=rows
  9. m=columns
  10. i:=0
  11. j:=0
  12. i=1
  13. If i<=n, go to step 14 or else go to step 20
  14. j=1
  15. If j<=m, go to step 16 or else go to step 18
  16. Print "*"
  17. j++. Go to step 15
  18. Go to next line
  19. i++. Go to step 13
  20. Stop

Program

Buffered Reader

import java.io.*;

class SolidRectangle 

    int rows, columns;
    void accept() throws IOException
    {
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        System.out.println("Enter the number of rows : ");
        rows = Integer.parseInt(br.readLne());
        System.out.println("Enter the number of columns : ");
        columns = Integer.parseInt(br.readLine());
    }

    void display(int n, int m)
    {
        int i, j;
        for (i = 1; i <= n; i++)
        {
            for (j = 1; j <= m; j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
    
    void main () throws IOException
    { 
        accept();
        System.out.println();
        display(rows, columns);
    } 
}

Scanner

import java.util.*;

class SolidRectangle 

    int rows, columns;
    void accept()
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number of rows : ");
        rows = sc.nextInt();
        System.out.println ("Enter the number of columns : ");
        columns = sc.nextInt();
    }

    void display(int n, int m)
    {
        int i, j;
        for (i = 1; i <= n; i++)
        {
            for (j = 1; j <= m; j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
    }
    
    void main ()
    { 
        accept();
        System.out.println();
        display(rows, columns);
    } 
}

Documentation

Variable Description

 Data TypeVariable NameDescription
 introws To store the number of rows 
 intcolumns To store the number of columns 
 intTo parse the value of rows to a function 
 intTo parse the value of columns to a function 
 intTo act as a counter variable 
 intTo act as a counter variable 

Method Description

 Return TypeMethod NameDescription
 voidaccept() To accept data from the user. 
 void display(int, int) To display the solid rectangle 
 voidmain() To act as an entry gateway for the compiler. 

Output


The Image is Unavailable




Share with all ISC Computer Science Students you know.

Comment below with all your program requests and blog suggestions.

Follow us on social media by clicking on these links. 
Instagram : @IscJavaCode
Twitter: @IscCode
Pinterest: @ISCJavaCode
Facebook: @ISCJavaCode


Stay Healthy
Stay Happy
Stay Helpful


Comments

You might also like:

Conversion of Complex Sentences to Simple Sentences

Conversion of Compound Sentences to Complex Sentences.

Conversion of Complex Sentences to Compound Sentences