0% found this document useful (0 votes)
2 views4 pages

Loop Programs (For Loop)

The document contains multiple Java programs that demonstrate the use of for-loops to perform various tasks, such as printing numbers in ascending and descending order, generating patterns, and creating a multiplication table. Each program is structured with a class definition and a main method where the for-loop logic is implemented. The output of each program is also provided, illustrating the expected results of the code.

Uploaded by

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

Loop Programs (For Loop)

The document contains multiple Java programs that demonstrate the use of for-loops to perform various tasks, such as printing numbers in ascending and descending order, generating patterns, and creating a multiplication table. Each program is structured with a class definition and a main method where the for-loop logic is implemented. The output of each program is also provided, illustrating the expected results of the code.

Uploaded by

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

Loop Programs

(for loop) output


//Write a program to print numbers from 1-10 using for-loop 1
public class Prg1 2
{ 3
public void main() 4
{ 5
int i; 6
for(i=1;i<=10;i++) 7
[Link](i); 8
} 9
} 10

//Write a program to print numbers from 10-1 in descending order 10


public class Prg2 9
{ 8
public void main() 7
{ 6
int i; 5
for(i=10;i>=1;i--) 4
[Link](i); 3
} 2
} 1
//Write a program to print the odd numbers from 1-19 using for loop 1
public class Prg3 3
{ 5
public void main() 7
{ 9
int i; 11
for(i=1;i<=19;i+=2) 13
[Link](i); 15
} 17
} 19

//Write a program to print the even numbers from 2-20 using 2


for loop 4
public class Prg4 6
{ 8
public void main() 10
{ 12
int i; 14
for(i=2;i<=20;i+=2) 16
[Link](i); 18
} 20
}
/*Write a program to generate the following pattern using for loop
* 5 10 15 20 ------50
*/

public class Prg5


{
public void main()
{
int i;
for(i=5;i<=50;i+=5)
[Link](i+" ");
}
}

Output: 5 10 15 20 25 30 35 40 45 50

/*Write a program to generate the following pattern using for loop


1 2 3 -------- 10*/

public class Prg6


{
public void main()
{
int i;
for(i=1;i<=10;i++)
[Link](i+" ");
}
}

Output: 1 2 3 4 5 6 7 8 9 10
//Write a program to print the multiplication table of 7 OUTPUT
1*7=7
public class Prg7 2*7=14
{ 3*7=21
public void main() 4*7=28
{ 5*7=35
for(i=1;i<=10;i++) 6*7=42
7*7=49
[Link](i+"*7="+(i*7)); 8*7=56
} 9*7=63
} 10*7=70

Write a pgm to print CNS 10 times. OUTPUT


CNS
CNS
CNS
public class Prg8 CNS
{ CNS
public void main() CNS
CNS
{ CNS
for(i=1;i<=10;i++) CNS
CNS

[Link](“CNS”);

You might also like