Java Practice Set - 3rd , Java String Practice Questions
Here are some Java strings practice questions that if you will practice enough you will end up becomming the good java developer in future
[1] Input 2 strings with the help of a scanner class and then add/concatenate those two strings
for eg: "Welcome to " + "my Channel ClassGenix " = "Welcome to my channel ClassGenix"
[2] Enter string and perform operations on that string as follows:
String = "A Quick Brown Fox Jumps Over A Lazy Fox"
[a] Find the length of the string
[b] Remove the space between each word
[c] Replace "O" with your name
[d] Convert it into UpperCase
[e] Convert it into LowerCase
[3] Find the length of the Following String
[a] "Hello My Name is Sachin Malhotra"
[b] "Wish you all the best"
[4] Find the last index of "a" in this string , "Name on your aadhar card"
[5] Compare 2 strings with the help of "equal()" method and "equalIgnoreCase()" method
[6] What will be the substring of the following
"Hello World , My Name is Josh"
[a] Substring(3,9);
[b] Substring(8);
Please Download the notes and practice set of this concept : Click Here
CODE SNIPPET IS SHOWN BELOW
package practice.set.pkg3;
import java.util.Scanner;
public class PracticeSet3 {
public static void main(String[] args) {
Scanner ref=new Scanner(System.in);
String Str1 = "Hello"; // first string
String Str2 = "World"; // second string
// in order to concatenate we must use arithmetic operator.
String Str3 = Str1+Str2;
System.out.println(Str3);
// second question
String Name = "A Quick Brown Fox Jumps Over A Lazy Fox";
String NameS=Name.replace(" ", "");
// " " = Space
// "" = No Space
System.out.println(NameS);
// question 4
String Str4 = "Name on your adhaar card";
int index=Str4.lastIndexOf("a");
System.out.println(index);
// question 6
String Josh = "Hello World, My Name is Josh";
String Josh2 = Josh.substring(3,9);
// Hello World , M y N a m e i s J o s h
// 01234567891011 12.........
// print =lo Wor
String Josh3 = Josh.substring(8);
System.out.println(Josh2);
System.out.println(Josh3);
}
}