-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp.java
More file actions
78 lines (66 loc) · 1.59 KB
/
p.java
File metadata and controls
78 lines (66 loc) · 1.59 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
import java.util.HashMap;
public class p {
public static void main(String[] args) {
String str="Hello";
has h=new has();
h.h();
char[] c=str.toCharArray();
Palin p=new Palin();
p.palindrome();
int left=0;
int right=c.length-1;
char temp;
while(left<right){
temp=c[left];
c[left]=c[right];
c[right]=temp;
left++;
right--;
}
System.out.println(new String(c));
String rev="";
for(int i=str.length()-1;i>=0;i--){
rev=rev+str.charAt(i);
}
System.out.println(rev);
}
}
class Palin{
void palindrome(){
String a="oiu";
int left=0;
int right=a.length()-1;
boolean ab=false;
while (left<right) {
if(a.charAt(left)!=a.charAt(right)){
ab=true;
// read the logic
break;
}
left ++;
right--;
}
if(ab){
System.out.println(" is a palindrome");
}
else{
System.out.println("is not a palindrome");
}
}
}
class has{
void h(){
HashMap <Character,Integer> map=new HashMap<>();
String h="Hello";
for ( int i=0;i<h.length();i++){
char ch=h.charAt(i);
if(map.containsKey(h.charAt(i))){
map.put(ch, map.get(ch)+1);
}
else{
map.put(ch, 1);
}
}
System.out.println(map);
}
}