In Java please. This is an exercise in using the String and stringBuilder classe
ID: 3790028 • Letter: I
Question
In Java please.
This is an exercise in using the String and stringBuilder classes @author (your name) @version (a version number or a date) */public class StringTesting public static void main(String[] args)//declare a reference to a StringBuilder object//declare a reference to a Scanner object//declare an int to hold the Unicode value of a character//create a Scanner object that will use the keyboard for input//create a StringBuilder object from the String//loop through the StringBuilder object character by character.//change each character to the next character in the Unicode//encoding scheme//print the original String and the StringBuilder contents//compile and run//set a breakpoint near the top of the code, //not on a declaration statement//step though the statement and exampline the variables}//end of main}//end of classExplanation / Answer
Hi, Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class StringTesting {
public static void main(String[] args) {
String refStr;
StringBuilder refBuilder;
Scanner keyboard;
int unicode;
keyboard = new Scanner(System.in);
System.out.print("Enter a string: ");
refStr = keyboard.nextLine();
refBuilder = new StringBuilder(refStr);
for(int i=0; i<refBuilder.length(); i++){
unicode = refBuilder.charAt(i);
unicode = unicode + 1;
refBuilder.setCharAt(i, (char)unicode);
}
System.out.println("String: "+refStr);
System.out.println("String bulder: "+refBuilder);
}
}
/*
Sample run:
Enter a string: sample
String: sample
String bulder: tbnqmf
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.