0% found this document useful (0 votes)
3 views2 pages

Programs

The document contains six Java code examples demonstrating various control flow structures such as loops and conditionals. Each example includes a main method that outputs specific patterns or sequences based on the logic implemented. The outputs of the programs are also provided, showcasing the results of the executed code.

Uploaded by

shanmugapriya
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)
3 views2 pages

Programs

The document contains six Java code examples demonstrating various control flow structures such as loops and conditionals. Each example includes a main method that outputs specific patterns or sequences based on the logic implemented. The outputs of the programs are also provided, showcasing the results of the executed code.

Uploaded by

shanmugapriya
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

1.

public class Test1 {

public static void main(String[] args) {

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

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

if(i*j > 4) break;

[Link](i*j + " ");

123243

2. public class Test2 {


public static void main(String[] args) {
int i = 0;
while(i < 5) {
i++;
if(i % 2 == 0) continue;
[Link](i + " ");
}
}
}

1 3 5
3. public class Test3 {
public static void main(String[] args) {
int x = 2;
switch(x) {
case 1: [Link]("A ");
case 2: [Link]("B ");
case 3: [Link]("C ");
default: [Link]("D ");
}
}
}
BCD
4. public class Test4 {
public static void main(String[] args) {
for(int i=1; i<=5; i++) {
if(i % 2 == 0) {
if(i % 3 == 0)
[Link]("X ");
else
[Link]("Y ");
} else {
[Link]("Z ");
}
}
}
}
ZYZYZ
5. public class Test5 {
public static void main(String[] args) {
int i = 1;
do {
if(i % 2 == 0)
[Link]("E ");
else
[Link]("O ");
i++;
} while(i <= 5);
}
}
OEOEO
6. public class Test6 {
public static void main(String[] args) {
for(int i=1; i<=3; i++) {
for(int j=1; j<=i; j++) {
if((i+j) % 2 == 0)
[Link]("* ");
else
[Link]("# ");
}
[Link]();
}
}
}
*
#*
*#*

You might also like