A Wonderful Hourglass Program
Hourglass Program: solved Java program for ISC Class 12 Computer Science with complete BlueJ code, explanation and sample output.
Write a program to take the input from the user for the row and column number. Print the no. of hourglass patterns that can be created from the given size of the matrix.

JAVA video
import java.io.*;
class Hourglass
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the row and column number for the matrix");
int r=Integer.parseInt(br.readLine());
int c=Integer.parseInt(br.readLine());
int num=10;
int Arr[][]=new int[r][c];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
Arr[i][j]=num++;
}
}
System.out.println("THE MATRIX IS---------------");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(Arr[i][j]+"\t");
}
System.out.println();
}
System.out.println("_______The hour glass patterns are_______");
for(int i=0;i<r-2;i++)
{
for(int j=0;j<c-2;j++)
{
int count=1;
for(int k=i;k<i+3;k++)
{
for(int l=j;l<j+3;l++)
{
if(count!=2)
{
System.out.print(Arr[k][l]+" ");
}
else
{
System.out.print(" "+Arr[k][l+1]);
break;
}
}
System.out.println();
count++;
}
System.out.println("------------------------------------------");
}
}
}
}Input:
Enter the row and column number for the matrix
4
5
THE MATRIX IS----------------------------------
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
_____The hour glass patterns are______
10 11 12
16
20 21 22
------------------------------------------
11 12 13
17
21 22 23
------------------------------------------
12 13 14
18
22 23 24
------------------------------------------
15 16 17
21
25 26 27
------------------------------------------
16 17 18
22
26 27 28
------------------------------------------
17 18 19
23
27 28 29
------------------------------------------
Data type
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.