Table Of Contents
1. Write a java code for n*N pattern
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i, j;
//Write your code here
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
System.out.print("*");
System.out.println();
}
}
2. Write A java Code for to Print Hollow N X N Box
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i, j;
//Write your code here
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
{
if(i == 1 || j == 1 || i == n || j == n)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
3. Write A java Code for to Print Diagonals of a N X N
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i, j;
//Write your code here
for(i = 1; i <= n; i++)
{
for(j = 1; j <= n; j++)
{
if(i == j || i + j == n+1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
4. Write A java Code for to print half pyramid of stars.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i, j;
//Write your code here
for(i = 1; i <= n; i++)
{
for(j = 1; j <= i ; j++)
System.out.print("*");
System.out.println();
}
}