-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopstasks.java
More file actions
108 lines (92 loc) · 4.02 KB
/
Copy pathLoopstasks.java
File metadata and controls
108 lines (92 loc) · 4.02 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*This collection of blocks of code contains tasks involving loops.
each challenge is each diffrent tasks , uncomment the block and use the code */
import java.util.Scanner;
public class Loopstasks {
public static void main(String[] args) {
Scanner ta=new Scanner(System.in);
/*challenge A: program to generate the multiplication table for a given number up to a specified limit.*/
// System.out.print("Write a number for making its Table: ");
// int p=ta.nextInt();
// System.out.print(" till How much: ");
// int k= ta.nextInt();
// for(int i=1; i<=k;i++){
// System.out.println(p+" X "+i+" = "+(p*i));
// }
/*challenge B: program to calculate the sum of all odd numbers between 1 and a specified input number.*/
// System.out.println("A program to sum all odd numbers between 1 and specified imput number ");
// System.out.print("Enter a number: ");
// int k=ta.nextInt();
// int oddSum=1;
// for(int i=2;i<=k;i++){
// if(i%2!=0){
// oddSum+=i;
// }
// }
// System.out.print(oddSum);
/*challenge C: A program to calculate the factorial of a given number.*/
// System.out.print("Enter a number to find factorial of: ");
// int numb= ta.nextInt();
// System.out.println("The Factorial of "+numb+" is : "+factorial(numb));
// must uncomment the function implemented at last
/*challenge D: program to calculate the sum of digits in a given integer.*/
//System.out.println("A Program to calculate the sum of digits in an integer ");
// System.out.print("Enter a number: ");
// long Entry=ta.nextLong();
// long length= (long) Math.log10(Entry)+1;
// long digiSum=0;
// for(int i=1;i<=length;i++){
// digiSum+=Entry%10;
// Entry=Entry/10;
// }
// System.out.println(" The Sum is: "+ digiSum);
/*challenge E: program to find the highest common factor (HCF) of two given numbers.*/
// System.out.println("Enter two numbers for finding HCF");
// int HCF=1;
// int max;
// System.out.print("Number 001: ");
// int a=ta.nextInt();
// System.out.print("Number 002: ");
// int b=ta.nextInt();
// if(a>b){max=b;}
// else {max=a;}
// for(int i=1;i<=max;i++) {if (a % i == 0 && b % i == 0) {HCF = i;}}
// System.out.println("THE HCF OF "+a+" and "+b+" is :"+HCF);
/*challenge F: program to find the least common multiple (LCM) of two given numbers.*/
// System.out.println("Enter two numbers for finding LCM");
// System.out.print("Number 001: ");
// int one1= ta.nextInt();
// System.out.print("Number 002: ");
// int one2= ta.nextInt();
// float LCM;
// for (int i=1;i<=one2;i++){
// LCM=one1*i;
// if(LCM%one2==0){
// System.out.println("LCM of the numers "+one1+" and "+one2+" is "+LCM);
// return;
// }
// }
/*challenge G: A program to check if a given number is prime or not.*/
// System.out.print("Enter a number to chack if prime: ");
// int primeornot= ta.nextInt();
// for(int i=2;i<primeornot;i++){
// if(primeornot%i==0){
// System.out.println("This is not Prime");
// return;
// }
// else {
// System.out.println("This is Prime ");
// return;
// }
// }
}
// public static int factorial(int n) {
// if (n == 0 || n == 1) {
// return 1;
// }
// int result = 1;
// for (int i = 2; i <= n; i++) {
// result *= i;
// }
// return result;
// }
}