0% found this document useful (0 votes)
17 views2 pages

Intermediate Programming - Lab 1

Uploaded by

uriel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Intermediate Programming - Lab 1

Uploaded by

uriel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LEC 1

String Manipulation

1. String concatenations
2. Changing the given string's case (e.g. from all caps [CAPS] to
lower case [caps])
3. Sub-string inside a string
4. Cleaning the string with the unwanted character
5. String reverse
6. Parsing
a. .parseInt() is used to get int data from a specific
string, i.e. It converts string to int

String Manipulation

String Manipulation Syntax


String System.out.println("");
concatenations str1 = "Hello";
str2 = "India";
System.out.println(str1 + " "
+ str2);
Changing a string's System.out.println("");
case str1 = "HELLO";
.toLowerCase() str2 = "hello";
System.out.println(str1.toLow
erCase());
.toUpperCase()
System.out.println(str2.toUpp
erCase());
Sub-string inside a a. System.out.println("");
string str1 = "My name is GFG";
System.out.println(str1);
.contain()
System.out.println(str1.con
tains("GFG"));
System.out.println(str1.con
tains("geeks"));
.substring() b. System.out.println("");
str1 = "Lorem ipsum dolor
sit amet, consectetur adipiscing
elit";
System.out.println(str1);
System.out.println(str1.sub
string(0, 10));
Cleaning the String System.out.println("");
.trim() str1 = " College of
Business and Technology ";
System.out.println(str1.trim(
));
String Reverse System.out.println("");
str1 = "Hello World!";
System.out.print("String
reverse: ");
for (int i = str1.length() -
1;i >= 0; i--){
System.out.print(str1.cha
rAt(i));
}

INTERMEDIATE PROGRAMMING Page 1


}
Parsing String age = "23";
.parseInt()
int futureage = Integer.parseInt(age)
+ 20;

System.out.println("Your age in 20
years is " + futureage);
.parseDouble() String exp;

System.out.println("Enter your daily


expenses: ");
exp = sc.next();

String exp2 = exp.substring(0);


double all =
Double.parseDouble(exp2);

double savings = 1000 - (all * 7);

System.out.println("Your savings is:


" + savings);

Different Kinds of System.out

System.out Syntax Output


.println() System.out.println
- Displays the ("Hello");
output on a System.out.println
new line ("World");

.print() System.out.print("
- Displays the Hello ");
output on the System.out.print("
same line World");
.printf() int age = 20;
- Allows to us to System.out.printf(
output string "I am %d years
formatted in old", age);
the code using
format
specifiers,
%s for a
string, %c for a
character,
and %d for an
integer.

INTERMEDIATE PROGRAMMING Page 2

You might also like