Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
317 lines (312 loc) · 10.8 KB

File metadata and controls

317 lines (312 loc) · 10.8 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import java.util.Scanner;
public class MyString {
public static void stringPrint(String str){
for(int i=0;i<str.length();i++){
System.out.print(str.charAt(i)+" ");
}
}
public static boolean Palindrome(String str){
for(int i=0;i<(str.length()/2);i++){
int n=str.length();
if (str.charAt(i)!=str.charAt(n-1-i)) {
return false;
}
}return true;
}
public static float ShortestPath(String str){
int x=0 , y=0 ;
for (int i=0;i<str.length();i++){
if (str.charAt(i)=='N') {
y++;
}
if (str.charAt(i)=='S') {
y--;
}
if (str.charAt(i)=='E') {
x++;
}
if (str.charAt(i)=='W') {
x--;
}
} int X2=x*x;
int Y2=y*y;
return (float)Math.sqrt(X2+Y2);
}
public static void stringEqual(String str1, String str2, String str3){
if (str1.equals(str2)) {
System.out.println("eqal");
} else {
System.out.println("not equal");
}
if (str1.equals(str2)) {
System.out.println("eqal");
} else {
System.out.println("not equal");
}
if (str1.equals(str3)) {
System.out.println("eqal");
} else {
System.out.println("not equal");
}
}
public static void subString(String str,int si,int ei){
String subString="";
for(int i=si;i<ei;i++){
subString+=str.charAt(i);
}System.out.println(subString);
System.out.println(str.substring(0,11));
}
public static void LexicographicallyLargestString(){
String fruits[]={"apple","mango","banana","ZEBRONICS"};
String largest=fruits[0];
for(int i=0;i<fruits.length;i++){
if (largest.compareToIgnoreCase(fruits[i])<0) {
largest=fruits[i];
}
}
System.out.println(largest);
}
public static void StringBuilder(){
StringBuilder sb=new StringBuilder("VedantUtpat_");
for(char ch='A';ch<='z';ch++){
sb.append(ch);
}System.out.println(sb);
}
public static void Capital1stLetter(String str){
StringBuilder sb=new StringBuilder("");
sb.append(Character.toUpperCase(str.charAt(0)));
for(int i=1;i<str.length();i++){
if (str.charAt(i)==' '&&i<str.length()-1) {
sb.append(str.charAt(i));
i++;
sb.append(Character.toUpperCase(str.charAt(i)));
}else{
sb.append(str.charAt(i));
}
}System.out.println(sb);
}
public static void compresString(String str){
StringBuilder sb= new StringBuilder();
for(int i=0;i<str.length();i++){
int count=1;
while (i<str.length()-1&&str.charAt(i)==str.charAt(i+1)) {
count++;
i++;
}
sb.append(str.charAt(i));
if (count>1) {
sb.append(count);
}
}System.out.println(sb);
}
public static boolean isvowel(char ch) {
ch=Character.toLowerCase(ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')return true;
return false;
}
public static void findUsernameNMailOpearator(String str) {
int i=str.indexOf("@");
String uname=str.substring(0,i);
String domain=str.substring(i+1, str.length());
System.out.println("Username :"+uname);
System.out.println("Domain :"+domain);
int j=domain.indexOf(".");
String name=domain.substring(0, j);
System.out.println(name.equals("gmail"));
System.out.println("if emailid contains gmail: " + str.contains("gmail"));
int indx = 0;
while (str.charAt(indx) != '@') {
System.out.print(str.charAt(indx));
indx++;
}
indx++;
System.out.println();
for (; indx < str.length(); indx++) {
System.out.print(str.charAt(indx));
}
}
public static void studentChallenge(String str) {
// we've to find if given strinng is binary-no. or not
System.out.println("valid binary no: " + str.matches("[0-1]+"));
// we've to find given string is hexadecimal or not
System.out.println("valid hexadecimal no: " + str.matches("[0-9A-F]+"));
// we've to find given string is valid date format or not [dd/mm/yyy]
System.out.println("valid date: " + str.matches("[0-3][0-9]/[0-1][0-9]/[0-9]{4}"));
}
public static void studentChallenge2(String str) {
// remove all the special-characters form string
System.out.println(str.replaceAll("[^a-z A-Z 0-9]", ""));
// remove extra spaces from string
System.out.println(str.replaceAll("\\s+", " ").trim());
//count number of words in a string
str=str.replaceAll("\\s+", " ").trim();
String words[]=str.split("\\s");
System.out.println(words.length);
}
public static void findRadix(String str){
if(str.matches("[0-1]+"))System.out.println("binary");
else if(str.matches("[0-7]+"))System.out.println("octal");
else if(str.matches("[0-9]+"))System.out.println("decimal");
else if(str.matches("[0-9 A-F]+"))System.out.println("hexadecimal");
else System.out.println("not a valid number");
}
public static void protocolTypeOfWEbsite(String str){
//protocol
System.out.println("Protocol is: "+str.substring(0,str.indexOf(":")));
//type of site
System.out.println("type of website is: "+str.substring(str.lastIndexOf("."),str.length()));
}
public static void numberToText(int n){
String str="";
while(n>0){
str+=(n%10);
n/=10;
}
for(int i=str.length()-1;i>=0;i--){
System.out.print(helpNumberToText(str.charAt(i))+" ");
}
}
public static String helpNumberToText(char c){
switch(c){
case '0':return "Zero";
case '1':return "One";
case '2':return "Two";
case '3':return "Three";
case '4':return "Four";
case '5':return "Five";
case '6':return "Six";
case '7':return "Seven";
case '8':return "Eight";
case '9':return "Nine";
}
return "Invalid";
}
public static void validateName(String name){
if(name.matches("[a-z A-Z]+"))System.out.println("Valid name: ");
else System.out.println("not a valid name:");
}
public static void anagrams(String s,String str){
if(s.length()!=str.length())System.out.println("not anagrams");
boolean check;
for(int i=0;i<str.length();i++){
check=false;
for(int j=0;j<s.length();j++){
if(str.charAt(i)==s.charAt(j)){
check=true;
break;
}
}
if(!(check)){
System.out.println("not anagrams");
break;
}
}
System.out.println("anagrams");
}
public static void allSubstrings(String str) {
for(int i=0;i<str.length();i++){
for (int j = i+1; j <=str.length(); j++) {
System.out.println(str.substring(i, j));
}
}
}
public static void toggleCharacters(String str) {
StringBuilder sb=new StringBuilder(str);
for(int i=0;i<sb.length();i++)
if(Character.isUpperCase(sb.charAt(i)))
sb.setCharAt(i, Character.toLowerCase(sb.charAt(i)));
else
sb.setCharAt(i, Character.toUpperCase(sb.charAt(i)));
System.out.println(sb);
}
public static void noOfPalindromicSubStrings(String str) {
int ans=0;
for(int i=0;i<str.length();i++){
for (int j = i+1; j <=str.length(); j++) {
if(isPalindrome(str.substring(i, j)))
ans++;
}
}
System.out.println(ans);
}
public static boolean isPalindrome(String str) {
StringBuilder sb=new StringBuilder(str);
if(str.equals(sb.reverse().toString()))return true;
return false;
}
public static String reverseString(String str) {
StringBuilder sb=new StringBuilder(str);
return sb.reverse().toString();
}
public static void reverseEachWord(String str) {
String words[]=str.split(" ");
StringBuilder ans=new StringBuilder();
for(String x:words)
ans.append(reverseString(x)+" ");
System.out.println(ans);
}
public static void compressString(String str) {
StringBuilder sb=new StringBuilder();
char last=str.charAt(0);
int count=1;
for(char x:str.toCharArray()){
if(x==last)count++;
else{
sb.append(last);
if(count>1)sb.append(count);
last=x;
count=1;
}
}
System.out.println(sb.append(last+""+count));
}
public static void oddEven(String str) {
if(str.length()==1)System.out.print(str.charAt(0));
else{
for(int i=1;i<str.length();i+=2){
System.out.print(str.charAt(i));
}
for(int i=0;i<str.length();i+=2){
System.out.print(str.charAt(i));
}}
}
public static void tTestCases(int n) {
Scanner sc=new Scanner(System.in);
for(int i=1;i<=n;i++){
String str=sc.nextLine();
int consonant=0,vowel=0,words=1;
for(char x:str.toCharArray()){
if(x==' ')words++;
else if(isvowel(x))vowel++;
else consonant++;
}
System.out.print(words+" "+vowel+" "+consonant+"\n");
}
sc.close();
}
public static void prefixEqualSuffix(String str) {
for(int i=0;i<str.length();i++){
String temp=str.substring(0, i);
if(str.lastIndexOf(temp)!=str.indexOf(temp)&&str.lastIndexOf(temp)==str.length()-temp.length()){
System.out.println(temp.length());
break;
}
}
}
public static void countWordsVowelsConsonants(String[] arr) {
for (int i = 1; i <=arr.length; i++) {
String str =arr[i].trim();
int consonant = 0, vowel = 0, words = 1;
for (char x : str.toCharArray()) {
if (x == ' ') words++;
else if (isvowel(x)) vowel++;
else consonant++;
}
System.out.print(words + " " + vowel + " " + consonant);
System.out.println();
}
}
public static void main(String[] args) {
prefixEqualSuffix("smartintsmart");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.