Program:-
public class PracticeSet5V25 {
public static void main(String []args){
/*Q1.write a program to print the following pattern:
****
***
**
*
*/
System.out.println("Q1:");
for(int i =4;i>0;i--){
for(int j =0;j<i;j++){
System.out.print("*");
}
System.out.println();
}
System.out.println("\n");
/*Q2. write a program to sum first n even numbers using while loop*/
System.out.println("Q2:");
int sum = 0;
int k = 0;
while(k<10){
sum = sum +(2*k);
k++;
}
System.out.print("sum of first ten even number is number is:");
System.out.println(sum+"\n");
/*Q3.write a program to print multiplication table of 8.*/
System.out.println("Q3:");
int l = 8;
for(int m= 1; m<=10;m++){
System.out.printf("%d*%d=%d\n",l,m,m*l);
}
System.out.println("\n");
/*Q4.write a program to print multiplication table of 10 in reverse order*/
System.out.println("Q4:");
int n = 10;
for(int o = 10; o>0;o--){
System.out.printf("%d*%d=%d\n",n,o,n*o);
}
System.out.println("\n");
/*Q5.write a program to find the factorial of a 5 using for loop*/
System.out.println("Q5:");
int factorial = 1;
for(int p = 5;p>0;p--){
factorial = factorial*p;
}
System.out.println("Factorial of 5 is: "+factorial);
System.out.println("\n");
/*repeat Q6 using while loop.*/
System.out.println("Q6:");
int fact = 1;
int q = 5;
while(q>0){
fact = fact*q;
q--;
}
System.out.println("the factorial of 5 is: "+fact);
System.out.println("\n");
/*Q7.repeat Q1 using while loop*/
System.out.println("Q7:");
int r = 4;
int s = 0;
while(r>0){
while(s<r){
System.out.print("*");
s++;
}
System.out.println();
r--;
s=0;
}
System.out.println("\n");
/*Q8.what can be done using one type of loop can also be done using the other two types of loop
ans: true*/
System.out.println("Q8:");
System.out.println("ans:true");
System.out.println("\n");
/*Q9. write a program to calculate the sum of the numbers occurring in hte multiplication table of 8*/
System.out.println("Q9:");
System.out.println("the multiplication table of 8 is:");
int t = 8;
int v = 0;
for(int u= 1; u<=10;u++){
System.out.printf("%d*%d=%d\n",t,u,u*t);
v = v+u*t;
}
System.out.println("the sum of multiplication table of 8 is:"+v);
System.out.println("\n");
/*Q10. A do-while loop is executed:
1.at least once
2.at least twice
3.at most once
and: 1. at least once*/
System.out.println("Q10:");
System.out.println("ans: 1. at least once");
System.out.println("\n");
/*Q11.repeat Q2 using for loop*/
System.out.println("Q11:");
int add = 0;
for(int w = 0; w<10; w++){
add = add +(2*w);
}
System.out.println("the sum of first ten even numbers is: "+add);
}
}

