Question

What value does this Processing code store in the s variable? String str = ""; int[]...

What value does this Processing code store in the s variable?

String str = "";
int[] a = {4, 8, 7, 8};
for (int i = 0; i < a.length; i++) {
  str = a[i] + str;
}
String s = str;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

String str = "";
int[] a = {4, 8, 7, 8};
for (int i = 0; i < a.length; i++) {
  str = a[i] + str;
  // i = 0, str is changed to 4
  // i = 1, str is changed to 84
  // i = 2, str is changed to 784
  // i = 3, str is changed to 8784
}
String s = str; // so, s is set to "8784"

Answer: "8784"
Add a comment
Know the answer?
Add Answer to:
What value does this Processing code store in the s variable? String str = ""; int[]...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA CODE String[] str = in.nextLine().split("\\s"); for(int i=0;i<=str.length;i++){ if (str[i].equals(stop)) break;    if(i%2==0){ System.out.print(str[i]+" "); }...

    JAVA CODE String[] str = in.nextLine().split("\\s"); for(int i=0;i<=str.length;i++){ if (str[i].equals(stop)) break;    if(i%2==0){ System.out.print(str[i]+" "); }    } lets say the INPUT for the array is: girl, boy, man, woman, girl, man, boy i dont want the array to print any string twice, i want the output to be like this: print all of them but print each once ---------- OUTPUT: girl, boy, man, woman

  • c++ Consider the following statement string str "Now is the time for the party!" What is...

    c++ Consider the following statement string str "Now is the time for the party!" What is the output of the following statements? (Assume that all parts are independent of each other.) a. cout <str·size ( ) end 1 ; b. Cout << str. substr (7, 8) <<endl: c. string: :size type indstr.find'£') string s str. substr (ind 4, 9); d. cout << str insert (11,"best " <<endl e. str.erase (16, 14) str.insert (16, "to study for the exam? ") cout...

  • QUESTION 10 What will be the output of following code snippet? char *str; str = "%s";...

    QUESTION 10 What will be the output of following code snippet? char *str; str = "%s"; printf(str, "S"); A. S B. Garbage Value C. Compile-time Error D. Run-time Error 4 points    QUESTION 11 What will be the output of the following statements assuming that the array begins at the memory address location 7002 and size of an integer is 4 bytes? int a[3][4] = { 1, 2, 3, 4,                     5, 6, 7, 8,                     9, 10, 11, 12 }; printf("%d,...

  • What does this code do? On the flipside of this paper, write the same code in...

    What does this code do? On the flipside of this paper, write the same code in Java. #include <stdio.h> #include <stdlib.h> int main ) ( char *str: (char *) malloc (15) ; str strcpy (str, "Iron"); printf("String 8u\n", str, str); Address %s, (char ) realloc (str, 25); str strcat (str, "Maiden"); Su\n", str, str): Address %s, printf ("String free (str) return (0); What does this code do? On the flipside of this paper, write the same code in Java. #include...

  • 1. Consider the following code segment. String str = "AP"; str += "CS " + 1...

    1. Consider the following code segment. String str = "AP"; str += "CS " + 1 + 2; System.out.println(str); What is printed as a result of executing the code segment? A: CS AP12 B: AP CS3 C: CSAP 12 D: APCS 12 E: APCS 3 2. Consider the following code segment. String dessert = "pie"; dessert += "straw" + dessert + "berry"; What is the value of dessert after the code segment has been executed? A: strawpieberry B: piestrawpieberry C:...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • The following code is a C Program that is written for encrypting and decrypting a string....

    The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...

  • CONSIDER THE FOLLOWING CODE: double SumString(string x, int n) {       double sum = 0;      ...

    CONSIDER THE FOLLOWING CODE: double SumString(string x, int n) {       double sum = 0;       for (int i = 0; i < n; i += 2)             sum += x.length();       return sum; } ///////////////////////////////////////////////////////// void Question() {       string a = "string";       int num = a.length();       double total = SumString(a, num);       cout << "The total is: " << total << endl; } Select one: a. The total is: 14.0 b. The total is: 20.0...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT