Interview Content
- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions
Rectangle Pattern Program In Java that Most Asked in Interview
And below Java concepts are used to print that patterns
- For Loop
- While Loop
- if..else
1). Program to print Solid Rectangle using star(*) in Java
import java.util.*;
class Main{
public static void main(String ...a){
int i;
System.out.println("This is Rectangle program");
Scanner sc= new Scanner(System.in);
System.out.print("enter the number of rows: ");
int rows= sc.nextInt();
Scanner sc1= new Scanner(System.in);
System.out.print("enter the number of columns: ");
int columns= sc1.nextInt();
for(i=1; i<=rows; i++)
{
for(j=1; j<=columns; j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
Output
2). Program to print hollow Rectangle using star(*) in Java
import java.util.*;
class Main{
public static void main(String ...a){
int i,j;
System.out.println("Hollow Reactangle Program");
Scanner sc= new Scanner(System.in);
System.out.print("enter the number of rows: ");
int rows= sc.nextInt();
Scanner sc1= new Scanner(System.in);
System.out.print("enter the number of columns: ");
int columns= sc1.nextInt();
for(i=1; i<=rows; i++)
{
for(j=1; j<=columns; j++)
{
if(i==1 || i==rows || j==1 || j==columns)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println("");
}
}
}
Output
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program