-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
60 lines (45 loc) · 1.09 KB
/
Main.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
package com.company;
public class Main {
public static void main(String[] args) {
//System.out.println(pow(2,4));
System.out.println(palindrome(121));
//System.out.println(binary(31));
}
//שאלה 1
public static int pow(int x, int index){
if(index == 1){
return x;
}
if(x == 0){
}
return pow(x, index-1) * x;
}
//שאלה 2
public static boolean palindrome(int num){
int x, sum=0, temp;
temp=num;
while(num > 0){
x = num % 10;
//System.out.println(x);
sum = (sum * 10) + x;
//System.out.println(sum);
palindrome(num /= 10);
//System.out.println(num);
}
if(temp == sum) {
return true;
}
else {
return false;
}
}
private static String binary(int num) {
if (num == 1) {
return "1";
}
if (num == 0) {
return "0";
}
return binary(num / 2) + num % 2;
}
}