0% found this document useful (0 votes)
10 views

Java Nested

Uploaded by

meermind54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Java Nested

Uploaded by

meermind54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// writing code for a patterin the java

import java.util.Scanner;
public class main{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 1; i<=n; i++){
for(int j = 1; j<=n; j++){
if(i==1 || j==1 || j==n || i==n|| i==j || j==n-i+1)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println("");
}
}
}
// 8
// ********
// ** **
// * * * *
// * ** *
// * ** *
// * * * *
// ** **
// ********

// printign right angle triangle with the help of the nested loop
public class main{
public static void main(String[]args){
for(int i = 1 ; i<=5; i++){
for(int j = 1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
// *
// **
// ***
// ****
// *****

// printign right angle triangle with the help of the nested loop
public class main{
public static void main(String[]args){
for(int i = 1 ; i<=5; i++){
for(int j = 1; j<=5; j++){
System.out.print("*");
}
System.out.println();
}
}
}
/* *****
*****
*****
*****
***** */

You might also like