Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4, Problem 9E
Write a loop that will create a new string that is the reverse of a given string.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a loop that counts the number of uppercase characters that appear in the string referenced by the variable mystring.
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the
sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore.
Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex:
The following patterns yield a userScore of 4:
simonPattern: RRGBRYYBGY
userPattern:
RRGBBRYBGY
324758.2040686.gx3zgy7
3
4 int main(void) {
1 test
char simonPattern[50];
char userPattern[50];
passed
6
7
int userScore;
8
int i;
All tests
passed
9
10
userScore = 0;
11
scanf ("%s", simonPattern);
scanf("%s", userPattern);
12
13
14
15
V* Your solution goes here */
16
17
printf("userscore: %d\n", userScore);
18
19
return 0;
20 }
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4:simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY
#include <iostream>#include <string>using namespace std;
int main() { string simonPattern; string userPattern; int userScore; int i;
userScore = 0;
cin >> simonPattern; cin >> userPattern;
/* Your solution goes here */
cout << "userScore: " << userScore << endl;
return 0;
Chapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Can the body of a while loop execute zero times?...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Revise the following code so that it uses a while...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Imagine a program that reads the population of a...Ch. 4.1 - Prob. 7STQCh. 4.1 - What output is produced by the following code? int...Ch. 4.1 - What output is produced by the following code? for...Ch. 4.1 - What output is produced by the following code? for...
Ch. 4.1 - Prob. 11STQCh. 4.1 - Write a for statement that displays the even...Ch. 4.1 - Prob. 13STQCh. 4.2 - Write a Java loop that will display the phrase One...Ch. 4.2 - Write a Java loop that will set the variable...Ch. 4.2 - Write a Java loop that will read a list of numbers...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - Revise the loop shown in Listing 4.6 to use a...Ch. 4.2 - What is the bug in the code in the section Tracing...Ch. 4.2 - Add some suitable output statements to the...Ch. 4.2 - What is the bug in the code in the previous...Ch. 4.2 - Prob. 24STQCh. 4.2 - Suppose that you did not have assertion checking...Ch. 4.3 - Prob. 26STQCh. 4 - Write a fragment of code that will read words from...Ch. 4 - Develop an algorithm for computing the...Ch. 4 - Develop an algorithm for a simple game of guessing...Ch. 4 - Write a fragment of code that will compute the sum...Ch. 4 - Convert the following code so that it uses nested...Ch. 4 - Write a for statement to compute the sum 1 + 22 +...Ch. 4 - (Optional) Repeat the previous question, but use...Ch. 4 - Write a loop that will count the number of blank...Ch. 4 - Write a loop that will create a new string that is...Ch. 4 - Write a program that will compute statistics for...Ch. 4 - Suppose we attend a party. To be sociable, we will...Ch. 4 - Define an enumeration for each of the months in...Ch. 4 - Write a fragment of code that computes the final...Ch. 4 - Suppose that you work for a beverage company. The...Ch. 4 - Suppose that we want to compute the geometric mean...Ch. 4 - Prob. 16ECh. 4 - Create an applet that draws a pattern of circles...Ch. 4 - Prob. 18ECh. 4 - What does the following fragment of code display?...Ch. 4 - Repeat Practice Program 4 of Chapter 3, but use a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Repeat Practice Program 5 of Chapter 3, but use a...Ch. 4 - Write a program to read a list of nonnegative...Ch. 4 - Write a program to read a list of exam scores...Ch. 4 - Combine the programs from Programming Projects 5...Ch. 4 - Write a program that simulates the Magic 8 Ball...Ch. 4 - Whats for dinner? Let the computer decide. Write a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Prob. 2PPCh. 4 - Write a program that reads a bank account balance...Ch. 4 - Modify Programming Project 5 from Chapter 2 to...Ch. 4 - Write a program that asks the user to enter the...Ch. 4 - Write a program that simulates a bouncing ball by...Ch. 4 - You have three identical prizes to give away and a...Ch. 4 - Prob. 9PPCh. 4 - Holy digits Batman! The Riddler is planning his...Ch. 4 - Your country is at war and your enemies are using...Ch. 4 - Prob. 12PPCh. 4 - Prob. 13PPCh. 4 - Prob. 14PPCh. 4 - Prob. 15PPCh. 4 - Prob. 16PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Design an algorithm that replaces each occurrence of the character x in the String variable str with a space.
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Private Sub Handles btnOutput.Click
End Sub
Introduction To Programming Using Visual Basic (11th Edition)
Explain the problems that denormalized tables may have for insert, update, and delete actions.
Database Concepts (8th Edition)
Code an SQL statement that creates a table with all columns from the parent and child tables in your answer to ...
Database Concepts (7th Edition)
Body Mass Index (BMI) helps in specifying the weight category a person belongs to, depending on their body weig...
Absolute Java (6th Edition)
If you have a PC, record the sequence activities that you can observe when you turn it on. Then determine what ...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY 324758.2040686.qx3zay7 4 int main(void) { char simonpattern[50]; char userPattern[50]; int userScore; int i; 6 7 8 9 userScore = 0; 10 11 12 scanf("%s", simonPattern); scanf ("%s", userPattern); 13 14 15 V* Your solution goes here */ 16 17 printf("userScore: %d\n", userscore); 18 19 return 0; 20 }arrow_forward"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY #include <iostream>#include <string>using namespace std; int main() {string simonPattern;string userPattern;int userScore;int i; userScore = 0; cin >> simonPattern;cin >> userPattern; /* Your solution goes here */ cout << "userScore: " << userScore << endl; return 0;} Please help me with this problem using c++.arrow_forward"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares each character of the two strings. For each matching character, add one point to user_score. Upon a mismatch, end the loop. Sample output with inputs: 'RRGBRYYBGY' 'RRGBBRYBGY' User score: 4 Code writing challenge activity demo 461710.3116374.qx3zqy7 1 user_score = 0 2 simon_pattern = input() 3 user_pattern = input() 4 5 Your solution goes here '' 6 7 print(f'User score: {user_score}') 111 pa All paarrow_forward
- "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares each character of the two strings. For each matching character, add one point to user_score. Upon a mismatch, end the loop. Sample output with inputs: 'RRGBRYYBGY' 'RRGBBRYBGY' User score: 4 Code writing challenge activity demo 461710.3116374.qx3zqy7 1 user_score = 0 2 simon_pattern 3 user_pattern 3456 4 TTV = = input() input() 5 Your solution goes here ""' 6 7 print (f'User score: {user_score}') F Farrow_forwardThe loop below is intended to collect all characters that occur more than once in a given string. When you try it out with a string such as “Mississippi”, you will note that that letters that occur three or more times are collected more than once. Modify the loop so that each repeated letter is collected exactly once. For example, when s is “Mississippi”, result should be “si” and not “sissii” Only allowed to edit code in the /* Your code goes here */ portion. Thanks for the help!arrow_forwardJava Programming: Using StringBuilder and a for loop, create a String that consists of the numbers 1 to 10 with a comma in-between. Make sure to use the loop to add the numbers to the String!arrow_forward
- subject: Assembly Language Write a program that displays a string in all possible combinations of foreground and background colors (16 x 16 =256). The colors are numbered from 0 to 15, so you can use a nested loop to generate all possible combinations.arrow_forwardwrite a loop that will display numbers in reverse order from 20 to 0arrow_forward"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares each character of the two strings. For each matching character, add one point to user_score. Upon a mismatch, end the loop.Sample output with inputs: 'RRGBRYYBGY' 'RRGBBRYBGY' User score: 4 user_score = 0simon_pattern = input()user_pattern = input() ''' Your solution goes here ''' print('User score:', user_score)arrow_forward
- write a loop that displays all ossible combinations of two letter there the letters are 'a', or 'b', 'c', 'd', or 'e'. the combinations should be displayed in ascending alphabetical order: aa ab ac etc using python and a nested looparrow_forward"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares each character of the two strings. For each matching character, add one point to user_score. Upon a mismatch, end the loop. Sample output with inputs: 'RRGBRYYBGY' 'RRGBBRYBGY' User score: 4 Learn how our autograder works 487180.3542414.qx3zqy7 1 user_score= 0 2 simon_pattern = input() 3 user_pattern input() 4 5 for i in range(len(simon_pattern)): 6 if simon_pattern[i] user_score=4 7 8 9 10 == user_pattern[i]:arrow_forwardfor( { } //missing String character = ) Your answer //missing 3 What should be added to the loop header to traverse through a string word? What should be added after the String character = ?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming Tutorial 36 - Intro to Loops; Author: Caleb Curry;https://www.youtube.com/watch?v=M3o7Y0juEP0;License: Standard YouTube License, CC-BY