0% found this document useful (0 votes)
6 views3 pages

Public Class p1

The document contains Java code for two classes: 'p1' and 'starProgram'. The 'p1' class has two versions of a main method that print patterns of '0's and '1's based on specific conditions. The 'starProgram' class prints a right-aligned triangle of asterisks.

Uploaded by

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

Public Class p1

The document contains Java code for two classes: 'p1' and 'starProgram'. The 'p1' class has two versions of a main method that print patterns of '0's and '1's based on specific conditions. The 'starProgram' class prints a right-aligned triangle of asterisks.

Uploaded by

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

public class p1{

public static void main(){

int k=1;

for(int i=1;i<=5;i++){

for(int j=1;j<=5;j++){

if(k%2==0) {

System.out.print("1");

} else {

System.out.print("0");

k++;

System.out.println();

public class p1{

public static void main(){

int k=1;

for(int i=1;i<=5;i++){

for(int j=1;j<=5;j++){

if(i%2==0){
System.out.print("0");

continue;

if(k%2==0) {

System.out.print("1");

} else {

System.out.print("0");

k++;

System.out.println();

public class starProgram{

public static void main(){

for(int i=1;i<=5;i++){

for(int j=1;j<=i;j++){

for(int k=4;k>=1;k--){

System.out.print(" ");

System.out.print("*");

System.out.println();

}
}

You might also like