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...
Hi, I am working on an assignment in C-Programming language dealing with LInked lists, in the...
Hi, I am working on an assignment in C-Programming language dealing with LInked lists, in the code there is instructions on where to write the code. I do not know how to write Linked Lists. Has to be in the C-language, Any help is greatly appreciated   //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void delink(void); void memexit(void); void wfile(void); /********************************************************************* this is the structure to hold a agent...
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...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you familiar with some of the most used JAVA syntax, as well as constructors objects, objects calling other objects, class and instance attributes and methods. You will create a small program consisting of Musician and Song classes, then you will have Musicians perform the Songs. Included is a file “Assignment1Tester.java”. Once you have done the assignment and followed all instructions, you should be able to...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT