Question

In: Computer Science

I have been working on this assignment in Java programming and can not get it to...

I have been working on this assignment in Java programming and can not get it to work.

This method attempts to DECODES an ENCODED string without the key.
  
public static void breakCodeCipher(String plainText){
char input[]plainText.toCharArray();
for(int j=0; j<25; j++){
for(int i=0; i<input.length; i++)
if(input[i]>='a' && input[i]<='Z')
input[i]=(char)('a'+((input[i]-'a')+25)%26);
else if(input[i]>='A'&& input[i]<='Z')
input[i]=(char)('A'+ ((input[i]-'A')+25)%26);
}
System.out.println(plainText)
  
}

Solutions

Expert Solution

There are a few compilation and semantic errors that I've seen in your code. They are:
-> input[] isn't initialised.
-> In the second loop '{}' aren't used, which makes the compiler think that it has to execute only the line next tot the loop.
-> The print statement doesnot have a semicolon.
-> Finally, you are printing the plaintext but not the decoded string.

I've made these fixes and included the code and output for you.

Code:

public class A
{
   public static void breakCodeCipher(String plainText)
   {
       char input[] = plainText.toCharArray();
       for(int j=0; j<25; j++)
       {
           for(int i=0; i<input.length; i++)
           {
               if(input[i]>='a' && input[i]<='Z')
                   input[i]=(char)('a'+((input[i]-'a')+25)%26);
               else if(input[i]>='A'&& input[i]<='Z')
                   input[i]=(char)('A'+ ((input[i]-'A')+25)%26);
           }
       }
       System.out.println(input);
   }
   public static void main(String args[])
   {
       breakCodeCipher("ZABCDE");
   }
}

Output:


Related Solutions

Hello i am working on an assignment for my programming course in JAVA. The following is...
Hello i am working on an assignment for my programming course in JAVA. The following is the assignment: In main, first ask the user for their name, and read the name into a String variable. Then, using their name, ask for a temperature in farenheit, and read that value in. Calculate and print the equivalent celsius, with output something like Bob, your 32 degrees farenheit would be 0 degrees celsius Look up the celsius to farenheit conversion if you do...
Java Programming: Can I get an example of a program that will allow 4 options? Example...
Java Programming: Can I get an example of a program that will allow 4 options? Example Output: Choose on of the options below: 1. Display all items in CSV file. (CSV file includes for example brand of phone, size, price) 2. Pick an item by linear searching 3. Pick an item by bineary searching 4. Quit Program
Question: Can I get the code in Java for this assignment to compare? Please and thank you....
Question: Can I get the code in Java for this assignment to compare? Please and thank you. Can I get the code in Java for this assignment to compare? Please and thank you. Description Write a Java program to read data from a text file (file name given on command line), process the text file by performing the following: Print the total number of words in the file. Print the total number of unique words (case sensitive) in the file. Print...
I have to code the assignment below. I cannot get the program to work and I...
I have to code the assignment below. I cannot get the program to work and I am not sure what i am missing to get the code to work past the input of the two numbers from the user. My code is listed under the assignment details. Please help! Write a Java program that displays the prime numbers between A and B. Inputs: Prompt the user for the values A and B, which should be integers with B greater than...
Been working on this one for a while - and can only get through part A......
Been working on this one for a while - and can only get through part A... for part B, I am trying 44.1+(28.836)(4.8x10-2x2pi)=52.8 and 44.1-(28.836)(4.8x10-2x2pi)=28.18 --> it keeps marking this wrong. A demonstration gyroscope wheel is constructed by removing the tire from a bicycle wheel 0.655 m in diameter, wrapping lead wire around the rim, and taping it in place. The shaft projects 0.200 m at each side of the wheel, and a woman holds the ends of the shaft...
Java Programming In this assignment we are going to create our own programming language, and process...
Java Programming In this assignment we are going to create our own programming language, and process it Java. programming language has 6 commands enter add subtract multiply divide return enter, add, subtract, multiply, divide all take 1 parameter (a double value). return takes no parameters.
This is a JAVA assignment and i dont have the SinglyLinkedList class   Exercise 1 In this...
This is a JAVA assignment and i dont have the SinglyLinkedList class   Exercise 1 In this exercise, you will add a method swapNodes to SinglyLinkedList class. This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same node, etc. Write the main method to test the swapNodes method. Hint: You may need to traverse the list. Exercise 2...
The programming language that is being used here is JAVA, below I have my code that...
The programming language that is being used here is JAVA, below I have my code that is supposed to fulfill the TO-DO's of each segment. This code in particular has not passed 3 specific tests. Below the code, the tests that failed will be written in bold with what was expected and what was outputted. Please correct the mistakes that I seem to be making if you can. Thank you kindly. OverView: For this project, you will develop a game...
Java Programming Assignment 6-1 We have covered the “Methods” this week. Apply the concepts that we...
Java Programming Assignment 6-1 We have covered the “Methods” this week. Apply the concepts that we have learnt in class and come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. You program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye”...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The coin class represents a coin. Any object made from it will have a 1) name, 2) weight and 3) value. As of now, the instance variables in Coin.java are all public, and the main function is calling these variables directly for the one coin made in it. Your goal is to enforce information hiding principles in this project. Take Coin.java, make all instance variables...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT