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 1e2df00

Browse files
authored
String functions
Signed-off-by: Boateng Prince Agyenim <163312213+Mmabiaa@users.noreply.github.com>
1 parent 59f3d88 commit 1e2df00

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package String;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
// 1. Printing Statements
6+
System.out.println("John said 'Java is fun and easy'");
7+
System.out.println("John said \"Java is fun and easy\"");
8+
9+
// 2. Converting Numeric Types to Characters
10+
char char1 = (char) 99; // 'c'
11+
char char2 = (char) 225; // 'á'
12+
13+
System.out.println("\nCharacter for 99: " + char1);
14+
System.out.println("Character for 225: " + char2);
15+
16+
// 3. Converting Characters to Integers
17+
char ch1 = 'A';
18+
char ch2 = '!';
19+
char ch3 = '*';
20+
char ch4 = 'i';
21+
22+
int int1 = (int) ch1; // ASCII value of 'A'
23+
int int2 = (int) ch2; // ASCII value of '!'
24+
int int3 = (int) ch3; // ASCII value of '*'
25+
int int4 = (int) ch4; // ASCII value of 'i'
26+
27+
System.out.println("\nASCII value of 'A': " + int1);
28+
System.out.println("ASCII value of '!': " + int2);
29+
System.out.println("ASCII value of '*': " + int3);
30+
System.out.println("ASCII value of 'i': " + int4);
31+
32+
// Optional: Get numeric value of a character
33+
char ch = '5';
34+
int numericValue = Character.getNumericValue(ch); // 5
35+
36+
System.out.println("\nNumeric value of '5': " + numericValue);
37+
}
38+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package String;
2+
3+
public class Welcome {
4+
public static void main(String[] args) {
5+
// Define the string
6+
String welcome = "Hello, welcome to Java";
7+
8+
// Get the length of the string
9+
int length = welcome.length();
10+
11+
// Display the length of the string
12+
System.out.println("The length of the string is: " + length);
13+
}
14+
}

0 commit comments

Comments
(0)

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