Question: Write a program that solves the following problem that combines use of Loops, String, and StringBuilder. There's a multiple - choice test with N questions,

Write a program that solves the following problem that combines use of Loops, String, and StringBuilder.
There's a multiple-choice test with N questions, numbered from 1 to N. Each question has 2 answer options, labelled A and B. You know that the correct answer for the ith question is the ith character in the string C, which is either "A" or "B", but you want to get a score of 0 on this test by answering every question incorrectly.
Your task is to implement the conversion which prints a string with N characters, the ith of which is the answer you should give for question i in order to get it wrong (either "A" or "B").Implement this using a StringBuilder object but print the String value of it.
Example:
C = ABA
N =3
Expected Output = BAB
C = BBBBB
N =5
Expected Output = AAAAA
import java.util.Scanner;
class Solution {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
String c1= scnr.next();
StringBuilder output1;
// Your code to convert the strings here
System.out.println(c1+" converts to "+ output1.toString());
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!