Write the output of the following program fragment String re
Write the output of the following program fragment.
String result = \"\"; // result is initially an empty string
result = result + alphabet.charAt(7);
result = result + alphabet.charAt(0);
result = result + alphabet.charAt(17);
result = result + alphabet.charAt(17);
result = result + alphabet.charAt(24)
int age = 30;
System.out.println(result + \" is \" + age + \" years old.\");
Solution
#include <iostream>
#include <cctype>
using namespace std;
int main(){
String result = \"\"; // result is initially an empty string
result = result + alphabet.charAt(7); // result=\'h\'
result = result + alphabet.charAt(0); // result=\'ha\'
result = result + alphabet.charAt(17); // result=\'har\'
result = result + alphabet.charAt(17); // result=\'harr\'
result = result + alphabet.charAt(24) // result=\'harry\'
int age = 30;
System.out.println(result + \" is \" + age + \" years old.\");
return 0;
}
//OUTPUT: harry is 30 years old.
