Consider you are asked to decode a secret message. The coded message is in numbers and each number stands for a
specific letter. You discover enough of the secret code to decode the current message. So far, you know:
• 1 represents “D”
• 2 represents “W”
• 3 represents “E”
• 4 represents “L”
• 5 represents “H”
• 6 represents “O”
• 7 represents “R”
Write a program that prompts the user for 10 numbers, one at a time, and prints out the decoded message. If the user
enters a number that is not one of those already deciphered, prompt him/her for a new number. Test your code with the
following input: 5 3 4 4 6 2 6 7 4 1

WRITE IN THE PROGRAMMING LANGUAGE: JAVA

Answers

Answer 1

Here is an example of a program in Java that prompts the user for 10 numbers, one at a time, and prints out the decoded message based on the code you provided:

import java.util.Scanner;

public class DecodeMessage {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Create a mapping of numbers to letters

char[] letters = {'D', 'W', 'E', 'L', 'H', 'O', 'R'};

int[] numbers = {1, 2, 3, 4, 5, 6, 7};

// Prompt the user for 10 numbers

StringBuilder decodedMessage = new StringBuilder();

for (int i = 0; i < 10; i++) {

System.out.print("Enter a number: ");

int input = scanner.nextInt();

// Check if the input is a valid number

boolean valid = false;

for (int j = 0; j < numbers.length; j++) {

if (input == numbers[j]) {

decodedMessage.append(letters[j]);

valid = true;

break;

}

}

// If the input is not a valid number, prompt the user again

if (!valid) {

System.out.println("Invalid number. Please enter a valid number.");

i--;

}

}

// Print the decoded message

System.out.println("Decoded message: " + decodedMessage.toString());

}

}

This program uses a Scanner to prompt the user for input, a StringBuilder to construct the decoded message, and two arrays letters and numbers to store the mapping of letters and numbers. The program uses a for loop to prompt the user for 10 numbers, and inside the loop, it checks if the input is a valid number (by checking if it exists in the numbers array) and, if it is, it appends the corresponding letter to the decoded message. If the input is not a valid number, the program prints an error message and the loop iterates again, prompting the user for a new number. Finally, it prints the decoded message.

The test input you provided will output "HELHOR"


Related Questions

How to fix Destiny 2 unable to playstation network?

Answers

Even though Bungie has highlighted that issue has indeed been rectified, a lot of players still have trouble with it. They look for answers in an effort to resolve this problem. They eventually discovered the answers in the Bungie.net forum, which other gamers had provided.

Way 1: Check if the PSN is down.

Way 2: Perform a power cycle on your router.

Way 3: Restart your PlayStation completely.

Way 4: Improve your Wi Fi speed.

Way 5: Update your router’s firmware.

Way 6: Modify your PlayStation DNS settings.

What causes the network error in Destiny 2?

If the problem still persists, players might want to try clearing the console cache or, if they're using a PC, the download cache. The problem could be fixed by restarting the router and/or internet modem. Check out our advice on reducing packet loss and latency to see if it can be of any assistance.

To know more about network visit:

brainly.com/question/15002514

#SPJ4

what is the type of attack that is occurring when sensitive information is screened and monitored, potentially compromising the security of enterprises and their customers?

Answers

Hackers conduct passive assaults by keeping an eye on systems and searching for openings or weaknesses that would allow them to steal information.

What do information security assaults entail?

A cyber attack is any attempt to obtain unauthorized access to a computer, computing system or computer network with the aim to do damage. The goal of a cyber attack is to disable, disrupt, destroy, or take control of a computer system, as well as to change, block, delete, modify, or steal the data stored on it.

What are attacks that are passive or active?

Active attacks involve the attacker attempting to alter the content of the message by intercepting the connection. In passive attacks, the attacker watches the messages, copies them, saves them, and subsequently can utilize them for bad intentions.

To know more about  sensitive information visit:-

https://brainly.com/question/28962905

#SPJ4

Which group on the Home tab contains the command for changing the fill color of a cell?
answer choices
File
Font
Alignment
Editing

Answers

In Excel, Font group on the Home tab contains the command for changing the fill color of a cell.

What is Font group in Excel?

In Excel, the Font group is a collection of tools that allow you to change the appearance of text in a cell or range of cells. These tools include options to change the font type, size, color, and style (bold, italic, underline, etc.). They can be found in the Home tab of the ribbon in the Excel interface.

The Font group in Excel allows you to easily change the appearance of text in your worksheet to make it stand out or match a specific design. You can apply formatting to a single cell, a range of cells, or an entire column or row. By using the options available in the Font group, you can customize the text in your worksheet to make it more readable, engaging and professional looking.

To learn more about Excel, visit: https://brainly.com/question/24749457

#SPJ4

REFRESH RECOMMENDED A newer version of this file is available on the server
Opening the file in the application I get at error message that says "Refresh recommended - A newer version of this file is available on the server." and the option to either "Save a Copy" or "Discard Changes" true or false

Answers

When I open the file in the program, I receive an error notice. as well as the choice to "Save a Copy" or "Discard Changes." true

How can I fix refresh advised Is there a more recent version of this file on the server?

Refresh is advised because there is a newer version of this file on the server. Given the choice to "Save a Copy" or "Discard Changes." You must erase the cache for the Microsoft Office application, thus Launch Finder. You can delete the "Data" folder by going to your profile or one of the following directories.

What does it mean to recommend a refresh?

Refresh is advised because there is a newer version of this file on the server. You are attempting to edit a document while a different client (phone, tablet, or laptop) is also viewing it. The document is now only viewable.

To know more about file server visit:-

https://brainly.com/question/14760328

#SPJ4

which kind of malware provides an attacker with administrative control over a target computer through a backdoor? A Remote Access Trojan (RAT) provides a backdoor for an attacker to remotely control a computer with administrative control. The other types of malware could be used in conjunction with a RAT, but they do not provide the remote control access.
PUP is software that contains adware, installs toolbars, or has other unclear objectives.
Crypto-malware is ransomware that encrypts files until a ransom is paid.
A Trojan horse is a malicious program that is disguised as legitimate or desirable software.

Answers

Answer: MACAFEE

Explanation:

Remote Access Trojan (RAT) is a kind of malware provides an attacker with administrative control over a target computer through a backdoor .

What is the RAT (Remote Access Trojan)?

Malware called "remote access trojans" (RATs) allow an infected computer to be controlled from afar by an intruder. The attacker can send commands to the RAT and receive data in response once it is running on a compromised system.

Backdoor attack :

A way to get into a computer system or encrypted data that gets around the system's usual security measures is called a backdoor attack. A backdoor can be created by a developer to allow access to an application, operating system (OS), or data for troubleshooting or other purposes. A backdoor is a type of malware that bypasses standard authentication to gain access to a system. As a result, an application grants remote access to resources like databases and file servers, allowing criminals to remotely issue system commands and update malware.

Learn more about backdoor attack:

brainly.com/question/14718381

#SPJ4

2. Which is not a utility software
a) Editor
b)Antivirus
c) Disk defragmenter
d) Snipping tool​

Answers

The best choice is option (b). Antivirus software, disc defragmenters, and text editors are examples of utility software.

What is utility software ?

The software package is software system that aids in maintaining a computer system's correct and efficient operation. It supports the Operating System in managing, organising, maintaining, and maximising the computer system's performance. Utility software completes activities such as virus detection, installation and uninstall, data backup, and the eradication of unnecessary files, among others. Antivirus, file management tools, disc management tools, etc. are a few examples. An antiviral is a piece of useful software that aids in preventing computer viruses.

Additionally, it alerts users when malicious files are found and deletes them. Additionally, it examines any new hardware that is connected to the computer and removes any viruses that are found. Additionally, it periodically monitors the system for dangers and eliminates them.

Therfore the correct option is  b)Antivirus

To know more about utility software visit:

brainly.com/question/2909686

#SPJ1

a search engine giant specializes in all types of search items; provides a free translation feature for 80 different languages; stores all passwords for commonly visited sites in encrypted form; allows users to view ads on previously made related searches; provides suggestive search items to assist the user; allows users to view a collection of related web pages users might want to visit; and provides a faster load time and more accurate hits than its rivals. this search engine company uses a profit formula that primarily consists of

Answers

The profit formula for this search engine company primarily consists of advertising revenue.

What is search engine?

A search engine is an online tool used to locate information on the Internet. Search engines use algorithms to search the Internet for webpages containing certain keywords and phrases. Once the search engine finds these webpages, it stores them in a database and displays them as search results

This revenue is generated through the ads that appear on related searches, as well as the monetization of user data. The company also benefits from the sale of paid services such as translation and the storage of passwords in an encrypted form. Finally, the company may also generate revenue from the sale of sponsored links, which appear on its search engine results pages. Additionally, the company may benefit from faster load times and more accurate search results, which can lead to increased user satisfaction and higher user engagement.

To learn more about search engine
https://brainly.com/question/512733
#SPJ4

Other Questions
Help pls I really need help Relationship type with 1:N cardinality ratio should always have a total participation constraint. a. True b. False propose a situation when a cell needs to utilize the process of transcription/translation to maintain homeostasis. How do bacteria reproduce?O BuddingMitosisO RegenerationO Meiosis Need help with question (3) Need answer of number 3,4,5 Let f(x) = 3x2 2x + 6 and g(x) = 7x 4. Identify the rule for f + g. do you dislike waiting in line? supermarket chain kroger has used computer simulation and information technology to reduce the average waiting time for customers at stores. using a new system called quevision, which allows kroger to better predict when shoppers will be checking out, the company was able to decrease average customer waiting time to just seconds (informationweek website). assume that waiting times at kroger are exponentially distributed. An executive at a U.S. steel company uses growth in gross domestic product as one way to develop trends in industry steel use, so he records GDP change for each year on a graph. However, the executive's figures are considerably higher than those of the staff economist, who also has drawn a graph. This difference is most likely the result of a teammate creates a new plot based on the chocolate bar data. the teammate asks you to make some revisions to their code. Assume your teammate shares the following code chunk:ggplot(data = best_trimmed_flavors_df) +geom_bar(mapping = aes(x = Cocoa.Percent)) +What code chunk do you add to the third line to create wrap around facets of the variable Cocoa.Percent?A. facet_wrap(~Cocoa.Percent)B. facet(=Cocoa.Percent)C. facet_wrap(%>%Cocoa.Percent)D. facet_wrap(Cocoa.Percent~) Find each percent of increase.round to the nearest percent 60 to 70 what would you do if you witnessed someone doing something wrong? The reciprocal of 10 1-2 finally, the client would have to reimburse dakota for every penny of actual expenses and costs incurred in-house, such as photocopies, plus any costs and expenses incurred from outside services providers, such as court reporters or experts. the client was astonished at the exorbitant fees, but she reluctantly agreed because she felt she had no real choice. dakota did memorialize their agreement in writing. is attorney dakota subject to discipline for this fee agreement? Answer this if you know how to create a works cited entry.. picture included.. help.. 2015 memorandum of agreement under which nasa is the lead agency for implementing cercla actions at nasa wff for fuds Write a real-world problem that you could represent with the equation 20 2n5 4. Solve the equation to find the answer to your problem Answer 8 and 9.Find the measure of an arc from the central angle. 26. Which of the following contains the correct in-text citation for the above sentence, with information from Source #1?*People have been using chilies in their food since 7500 BC (Tang).People have been using chilies in their food since 7500 BC (Lonely Planet 2014).People have been using chilies in their food since 7500 BC. (Tang)People have been using chilies in their food since 7500 BC. (Lonely Planet 2014)No in-text citation is needed. Matthew and David have $689.45. If David has $346.90, how much does Matthew have? Right and solve an additional equation to find how much money belongs to Matthew.