This is an exercise in using the String and StringBuilder classes @author (your
ID: 3789799 • Letter: T
Question
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 String object://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 String object with input from the user//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
package elastic5.elastic5;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class ttt {
public static void main(String[] args) {
// declare a reference of String object;
String s = null;
// declare a reference of StringBuilder object;
StringBuilder sb;
// declare a reference of Scanner object;
Scanner sc;
// declare a int hold value of character
int cc = 0x2202;
// scanner taking value from keyword
Scanner keyboard = new Scanner(System.in);
System.out.println("enter a Stringr");
s = keyboard.next();
// string object creation
String keywordString = new String(s);
// String to stringbuilder
StringBuilder sbuilder = new StringBuilder(keywordString);
System.out.println("sbuilder" + sbuilder);
// loop through stringbuilder to character
// change character to next character and change in unicode
StringBuilder ssnew = new StringBuilder();
for (int i = 0, n = sbuilder.length(); i < n; i++) {
char c = sbuilder.charAt(i);
System.out.println("c" + c);
ssnew.append(String.format("\u%04x", (int) sbuilder.charAt(i++)));
}
System.out.println("string==" + s);
System.out.println("Unicode Stringbuilder " + ssnew);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.