-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainPra.java
117 lines (90 loc) · 3.08 KB
/
MainPra.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class MainPra {
/*This class contains
- word counter method
- password verifier method
- mostFrequent method
- replaceSubString method
- wordCount method
*/
public static void main(String[] args) {
Map<Integer,String> map = new LinkedHashMap<>();
map.put(12,"tewelve");
map.put(13,"foretewelve");
map.put(14,"theerewelve");
System.out.println(map.values() + " " + map.get(12));
String str1 = "thheeeeaaaaaaaaaaahhee";
String str2 = "the";
String str3 = "thaaaat";
System.out.println(mostFrequent(str1));
System.out.println(replaceSubString(str1,str2,str3));
String str = "12345";
String[] a = str.split("");
int i = 0;
char[] ch = str.toCharArray();
for(char c:ch){
i += Integer.parseInt(String.valueOf(c));
}
System.out.println("result : " + i);
// System.out.print("Enter your sentence : ");
// String str = new Scanner(System.in).nextLine();
// System.out.println(wordCounter(str));
// System.out.print("Enter your password : ");
// str = new Scanner(System.in).nextLine();
// System.out.println(passwordVerify(str)?"acceptable password":"wrong password");
}
public static String wordCounter(String str){
String[] s = str.split("[ ]");
return "NO of words : " + s.length;
}
public static boolean passwordVerify(String password){
int digit = 0;
int upperCase = 0;
int lowerCase = 0;
if(password.length() < 6){
System.out.println("password must have 6 or greater length");
System.exit(0);
}
for(int i =0;i < password.length();i++){
if(Character.isDigit(password.charAt(i)))
digit++;
else if(Character.isUpperCase(password.charAt(i)))
upperCase++;
else if(Character.isLowerCase(password.charAt(i)))
lowerCase++;
}
return digit > 0 && upperCase > 0 && lowerCase > 0;
}
public static long wordCount(String str){
String[] words = str.split(" ");
return Arrays.stream(str.split(" ")).count();
}
public static String arrayToString(char[] ch){
String str = String.valueOf(ch);
return str;
}
public static char mostFrequent(String str){
char mostFre = ' ';
int count = 0;
String[] arr = str.split("");
for(int i =0;i<str.length();i++){
int temp = 0;
for(int j =0;j<str.length();j++){
if (arr[i].equalsIgnoreCase(arr[j])){
temp += 1;
}
}
if(temp > count){
count = temp;
mostFre = arr[i].charAt(0);
}
}
return mostFre;
}
public static String replaceSubString(String str1, String str2, String str3){
return str1.replace(str2,str3);
}
}