Skip to content

Commit dc7096f

Browse files
completed
1 parent c63d588 commit dc7096f

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

BasicJavaProblems/Factorial.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package BasicJavaProblems;
2+
3+
public class Factorial {
4+
5+
static int withMultOperator(int n) {
6+
7+
System.out.println("With using Multiplication operator");
8+
int sum = 1;
9+
for (int i = 2; i <= n; i++)
10+
sum *= i;
11+
return sum;
12+
}
13+
14+
static int withOutMultOperator(int n) {
15+
System.out.println("Without using Multiplication operator");
16+
int temp = n;
17+
for (int i = n - 1; i > 0; i--) {
18+
int sum = 0;
19+
for (int j = 0; j < i; j++)
20+
sum += temp;
21+
// System.out.println(sum+" "+i);
22+
temp = sum;
23+
}
24+
return temp;
25+
26+
}
27+
28+
public static void main(String[] args) {
29+
System.out.println(withMultOperator(5));
30+
System.out.println(withOutMultOperator(5));
31+
}
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package BasicJavaProblems;
2+
3+
public class MaxRepeatedNumber {
4+
public static void main(String[] args) {
5+
int a[] = { 5, 1, 2, 6, 2, 5 }, max = Integer.MIN_VALUE;
6+
for (int i = 0; i < a.length; i++)
7+
if (max < a[i])
8+
max = a[i];
9+
// System.out.println(max);
10+
int b[] = new int[max + 1];
11+
12+
for (int i = 0; i < a.length; i++) {
13+
b[a[i]]++;
14+
}
15+
16+
System.out.println("Counted :");
17+
for (int i : b)
18+
System.out.print(+i + " ");
19+
20+
System.out.println();
21+
int MaxRepeatedNumberMin = 0, min = 0;
22+
for (int i = 0; i < b.length; i++) {
23+
if (MaxRepeatedNumberMin < b[i]) {
24+
MaxRepeatedNumberMin = b[i];
25+
min = i;
26+
}
27+
}
28+
System.out.println("MaxRepeatedNumberMin " + min);
29+
}
30+
}

BasicJavaProblems/gcd.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package BasicJavaProblems;
2+
3+
public class gcd {
4+
5+
static int GeneralMethod(int a, int b) {
6+
int gcd = 0;
7+
for (int i = 1; i <= a && i <= b; i++) {
8+
if (a % i == 0 && b % i == 0)
9+
gcd = i;
10+
}
11+
return gcd;
12+
}
13+
14+
static int eludienSub(int a, int b) {
15+
if (b == 0)
16+
return a;
17+
else
18+
return eludienSub(b, Math.abs(a - b));
19+
}
20+
21+
static int eludienMod(int a, int b) {
22+
if (b == 0)
23+
return a;
24+
else
25+
return eludienSub(b, (a % b));
26+
}
27+
28+
public static void main(String[] args) {
29+
System.out.println("General Method :");
30+
System.out.println(GeneralMethod(20, 30));
31+
System.out.println("Eudien Algorithm(Subtraction)");
32+
System.out.println(eludienSub(20, 30));
33+
System.out.println("Eudien Algorithm(%)");
34+
System.out.println(eludienMod(20, 30));
35+
}
36+
}

0 commit comments

Comments
 (0)