-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_16_practice06.java
91 lines (71 loc) · 2.41 KB
/
A_16_practice06.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.company;
import java.sql.SQLOutput;
import java.util.Scanner;
public class A_16_practice06 {
public static void main(String[] args) {
////Question 1: print the pattern loop.
// int n =4;
// for(int i=n; i>0; i--) {
// for (int j = 0; j < i; j++) {
// System.out.print("*");
// }
// System.out.print("\n");
// }
////Question 2: Write a program to sum first n even numbers using While loop.
// int n = 4 , i =0;
// int sum = 0;
// while(i<=n){
// sum = sum +(2*i);
// i++;
// }
// System.out.printf("Sum of first %d even number is: %d", n , sum);
////Question 3: multiplication table
// int n = 5;
// for(int i =1; i<=10 ; i++){
// System.out.printf("%d * %d = %d\n", n, i , n*i);
// }
////Question 4: Multiplication table of 10 in reverse order.
// for(int i =10; i>0; i--){
// System.out.printf("10 * %d = %d\n", i ,10*i);
// }
////Question 5: Factorial
// Scanner sc = new Scanner(System.in);
// System.out.print("Enter a number: ");
// int n = sc. nextInt();
// int fact = 1;
// for(int i = 1 ; i<=n ; i++){
// fact *= i ; // fact = fact * i
// }
// System.out.printf("factorial of %d is : %d", n , fact);
////Question 6: Factorial (Using While loop)
// Scanner sc = new Scanner(System.in);
// System.out.println("enter a number: ");
// int n = sc.nextInt();
// int fact = 1 , i= 1;
// while(i<=n){
// fact *=i;
// i++;
// }
// System.out.printf("factorial of %d is: %d ", n , fact);
//Question 7:Question 1 using for/while loop:
// int i =4;
// while(i>0) {
// int j =0;
// while(j < i) {
// System.out.print("*");
// j++;
// }
// System.out.print("\n");
// i--;
// }
//Question 8: What can be done using one type of loop can also be done using the other two types of loops - True or False.
//Answer: True
////Question 9: To calculate the sum of the numbers occur in the multiplication table of 8.
// int sum = 0;
// for(int i = 1 ; i<=10; i++){
// sum += 8*i; // sum = sum + (8*i)
// }
// System.out.print("sum = ");
// System.out.println(sum);
}
}