Help with this please. I need to explain the program line by line. Annotate each
ID: 3766473 • Letter: H
Question
Help with this please. I need to explain the program line by line.
Annotate each line with the action it preforms using //annotation by the side of the line.
class Alpha
{
public static void main(String[] args)
{
StringBuilder sb = new StringBuilder(26);
for (char ch = 'A'; ch <= 'G'; ch++)
sb.append(ch);
sb.append("u03b1");
sb.append("u03B2");
sb.append("u03c0");
System.out.println(sb.charAt(2));
System.out.println(sb.charAt(4));
System.out.println(sb.charAt(7));
System.out.println(sb.charAt(8));
System.out.println(sb.charAt(9));
}
}
Explanation / Answer
class Alpha
{
public static void main(String[] args)
{
StringBuilder sb = new StringBuilder(26);//StringBuilder is mutable sequence of characters designed for use as a drop-in replacement for StringBuffer.it implemented under most because it is faster
for (char ch = 'A'; ch <= 'G'; ch++)//repeating loop A to G by specifying data type as char
sb.append(ch);//this method appends the string representation of the char argument in sequence
sb.append("u03b1");//Here unicode 03b1 appended to the string
sb.append("u03B2");//Here unicode 03B2 appended to the string
sb.append("u03c0");//Here unicode 03c0 appended to the string
System.out.println(sb.charAt(2));//It prints the char value at the specified index value of 2
System.out.println(sb.charAt(4));//It prints the char value at the specified index value of 4
System.out.println(sb.charAt(7));//It prints the char value at the specified index value of 7
System.out.println(sb.charAt(8));//It prints the char value at the specified index value of 8
System.out.println(sb.charAt(9));//It prints the char value at the specified index value of 9
}
}
OUTPUT:
ABCDEFG03b10B203c0
CE03b
Thank you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.