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

Sign up
Appearance settings

Commit d7e4836

Browse files
Strings
1 parent e469ebd commit d7e4836

File tree

4 files changed

+205
-0
lines changed

4 files changed

+205
-0
lines changed

‎String/Colindrome.java‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package String;
2+
3+
import java.util.Scanner;
4+
5+
public class Colindrome {
6+
public static String[] split(String s) {
7+
String t = "";
8+
String r[] = new String[(s.length() / 6)];
9+
for (int i = 0; i < s.length() / 6;) {
10+
for (int j = 0; j < s.length(); j++) {
11+
if ((j + 1) % 6 == 0) {
12+
t += s.charAt(j);
13+
r[i++] = t;
14+
t = "";
15+
} else
16+
t += s.charAt(j);
17+
}
18+
}
19+
for (String x : r) {
20+
System.out.println(x);
21+
}
22+
return r;
23+
}
24+
25+
public static void main(String[] args) {
26+
Scanner sc = new Scanner(System.in);
27+
System.out.println("Enter the String: ");
28+
String s = sc.nextLine();
29+
sc.close();
30+
int flag = 0;
31+
if (s.length() < 6 && (s.length() % 6 != 0))
32+
System.out.println("Not a colindrome!");
33+
String[] res = split(s);
34+
for (int i = 0; i < res.length; i++) {
35+
if (!isColindrome(res[i]))
36+
flag = 1;
37+
}
38+
if (flag == 0) {
39+
System.out.println("String is colindrome");
40+
} else {
41+
System.out.println("Not a colindrome!");
42+
}
43+
44+
}
45+
46+
public static boolean isColindrome(String s) {
47+
int k = 2, j = 3;
48+
while (k > 0) {
49+
if (s.charAt(k) != s.charAt(j))
50+
return false;
51+
k--;
52+
j++;
53+
}
54+
return true;
55+
}
56+
}

‎String/ExchangeAlter.java‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package String;
2+
3+
import java.util.Scanner;
4+
5+
public class ExchangeAlter {
6+
public static String[] split(String s) {
7+
int c = 0;
8+
for (int i = 0; i < s.length(); i++) {
9+
if (s.charAt(i) == ' ') {
10+
c += 1;
11+
}
12+
}
13+
String[] st = new String[c + 1];
14+
String t = "";
15+
int j = 0;
16+
for (int i = 0; i < s.length(); i++) {
17+
if (s.charAt(i) != ' ') {
18+
t += s.charAt(i);
19+
} else {
20+
st[j++] = t;
21+
t = "";
22+
}
23+
}
24+
st[j] = t;
25+
return st;
26+
}
27+
28+
public static void main(String[] args) {
29+
Scanner sc = new Scanner(System.in);
30+
System.out.println("Enter the String: ");
31+
String s = sc.nextLine();
32+
sc.close();
33+
String[] str = split(s);
34+
String temp = "";
35+
temp = str[0];
36+
str[0] = str[str.length - 1];
37+
str[str.length - 1] = temp;
38+
for (String s1 : str) {
39+
System.out.print(s1 + " ");
40+
}
41+
}
42+
}

‎String/LargeWordCount.java‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package String;
2+
3+
public class LargeWordCount {
4+
5+
public static String[] split(String s) {
6+
int c = 0;
7+
for (int i = 0; i < s.length(); i++) {
8+
if (s.charAt(i) == ' ')
9+
c++;
10+
}
11+
String[] temp = new String[c + 1];
12+
String t = "";
13+
int i=0;
14+
for (int j = 0; j < s.length(); j++) {
15+
if (s.charAt(j) != ' ') {
16+
t += s.charAt(j);
17+
} else {
18+
temp[i++] = t;
19+
t = "";
20+
}
21+
}
22+
temp[i] = t;
23+
return temp;
24+
}
25+
public static void sort(String[] s) {
26+
for(int j=0;j<s.length;j++) {
27+
for(int i=0;i<s.length-(j+1);i++) {
28+
if(s[i].length()>s[i+1].length()) {
29+
String t=s[i];
30+
s[i]=s[i+1];
31+
s[i+1]=t;
32+
}
33+
}
34+
}
35+
}
36+
public static String sortAndCount(String[] sp) {
37+
sort(sp);
38+
String sx="";
39+
int n;
40+
for(int k=0;k<sp.length-1;k++) {
41+
if(sp[k].length()!=sp[k+1].length()) {
42+
n=sp[k].length();
43+
sx+=sp[k]+n+" ";
44+
}else {
45+
sx+=sp[k]+" ";
46+
}
47+
}
48+
sx+=sp[sp.length-1]+sp[sp.length-1].length();
49+
return sx;
50+
}
51+
public static void main(String[] args) {
52+
String s = "the white tiger is bigger than the brown tiger";
53+
// output : is 2 the 3 than 4 white tiger brown 5 bigger 6
54+
String[] sp=split(s);
55+
for(String n:sp) {
56+
System.out.print(n+" ");
57+
}
58+
System.out.println();
59+
String res=sortAndCount(sp);
60+
System.out.println(res);
61+
62+
}
63+
}

‎String/PasswordValidation.java‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package String;
2+
3+
import java.util.Scanner;
4+
5+
public class PasswordValidation {
6+
static final String SPECIAL_CHARACTERS = "!,#,,ドル%,^,&,*,|";
7+
static String password;
8+
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
System.out.print("Enter the Password: ");
12+
password = sc.nextLine();
13+
sc.close();
14+
15+
if (isValidPassword(password)) {
16+
System.out.println("Password is in correct format!");
17+
} else {
18+
System.out.println("Not a valid password!");
19+
}
20+
}
21+
22+
public static boolean isValidPassword(String pass) {
23+
boolean loCase = false;
24+
int isDigit = 0;
25+
boolean spChar= false;
26+
27+
if (pass.length() < 8) {
28+
return false;
29+
} else {
30+
for (int i = 0; i < pass.length(); i++) {
31+
if (pass.matches(".+[a-z].+")) {
32+
loCase = true;
33+
}
34+
if (pass.matches(".+[1-9].+")) {
35+
isDigit++;
36+
}
37+
if (SPECIAL_CHARACTERS.contains(pass.substring(i, i+1))) {
38+
spChar=true;
39+
}
40+
}
41+
}
42+
return loCase && (isDigit >= 2) && !spChar;
43+
}
44+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /