StringBuilder is used to modify strings easily but you can StringBuffer class for thread safe operations which will be discuss in the concurrency topic.
===================
import java.util.Scanner;
class Class0701 {
static boolean findingEggs(String word){
int wordLength = word.length();
String eggs = "eggs";
int eggsLength = eggs.length();
boolean foundIt = false;
for(int i=0; i<wordLength; i++){
if(word.regionMatches(i, eggs, 0, eggsLength)){
foundIt = true;
break;
}
}
return foundIt;
}
static String reversingWord(String word){
StringBuilder stringBuilder = new StringBuilder(word);
stringBuilder.reverse();
return stringBuilder.toString();
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter any string: ");
String input3 = "";
String temp;
while(true){
temp = scan.next();
if(temp.equals("out")){
break;
}else {
input3 = input3.concat(temp);
}
}
System.out.println("Your entered: \t" + input3);
System.out.println("Did find eggs: \t" + findingEggs(input3));
System.out.println("Reverse: \t" + reversingWord(input3));
}
}===================
Result:
Enter any string: hambaconeggsspaghettioutYour entered: hambaconeggsspaghettiDid find eggs: trueReverse: ittehgapssggenocabmah
Note: The string was easily reverse in the StringBuilder class since it is a predefined class though in the String class itself, there are other important methods just like the length() method to find the length of the string. It will take a long time to specify all the methods. So, I chose some just to get a better grasp of the situation.
YOU ARE READING
Java Programming
אקראיhttps://docs.oracle.com/javase/tutorial/ This is the link where I learned my java lessons online. I choose java as first programming language. I am a career shifter. I just want to start something new. I choose to write it here in Wattpad so that I...