Uploaded by Balwant Singh

Write Java programming for the below given exercise upon String

advertisement
Write Java programming for the below given exercise upon String
Question 1:
Write a Java program that takes a user-input string and outputs its length.
Question 2:
Create a program that concatenates three strings: "Java", "is", and "fun!" using both the + operator and
concat() method.
Question 3:
Write a Java program to find the first occurrence of the word "sample" in the given string "This is a sample
text" and print the substring starting from that index.
Question 4:
Enhance the previous program to find and print all occurrences of the word "sample" in the given string.
Question 5:
Create a program that performs a case-insensitive search for the word "hello" in the user-input string.
Question 6:
Write a program that replaces all occurrences of the word "apple" with "orange" in the given string "I have
an apple, and she has an apple too."
Question 7:
Create a program that takes a user-input string and splits it into an array of words.
Question 8:
Create a Java program to compare two strings "hello" and "Hello" for equality using the equals() method.
Also, perform a case-insensitive comparison using equalsIgnoreCase().
Download