-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringPrograms.java
More file actions
80 lines (70 loc) · 1.97 KB
/
StringPrograms.java
File metadata and controls
80 lines (70 loc) · 1.97 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
79
80
/*Method Use
length() Length of string
charAt(i) Character at index
toUpperCase() Convert to uppercase
toLowerCase() Convert to lowercase
equals() Compare strings
equalsIgnoreCase() Ignore case
substring() Extract part
contains() Check word
replace() Replace characters
concat() merge two string
trim() used to remove space*/
//! reverse a String
class Reverse{
public static void main(String[]args){
String word="Java";
String reverse="";
for(int i= word.length()-1;i>=0;i--){
reverse+= word.charAt(i);
}
System.out.println(reverse);
}
}
//! Check Palindrome
//Write a Java program to check whether a string is palindrome or not.
class Palindrome{
public static void main(String...args){
String s="madam";
String rev="";
for(int i= s.length()-1;i>=0;i--){
rev+=s.charAt(i);
}
if(s.equals(rev)){
System.out.println("Palindrome");
}
else{
System.out.println(" Not a Palindrome");
}
}
}
//! WAJP if a string is palindrome show true other wise show false.
class Palindrome1{
public static void main(String[]args){
String word="malayalam";
System.out.println(isPalindrome(word));
}
static boolean isPalindrome(String s){
if(s.length()==0) return true;
String reverse="";
for(int i=s.length()-1;i>=0;i--){
reverse= reverse+s.charAt(i);
}
return s.equals(reverse);
}
}
//! WAJP to find sum of all digits inside a string.
class SumOfCharDigit{
public static void main(String[]args){
String s="1su23bhka41ti";
int sum=0;
for(int i=0;i<s.length();i++){
char ch=s.charAt(i);
if(ch>='0'&& ch<='9'){
sum=sum+(ch-'0');
}
}
System.out.println(sum);
}
}
/// just a comment