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...
Hi I have a java code for my assignment and I have problem with one of...
Hi I have a java code for my assignment and I have problem with one of my methods(slice).the error is Exception in thread "main" java.lang.StackOverflowError Slice method spec: Method Name: slice Return Type: Tuple (with proper generics) Method Parameters: Start (inclusive) and stop (exclusive) indexes. Both of these parameters are "Integer" types (not "int" types). Like "get" above, indexes may be positive or negative. Indexes may be null. Description: Positive indexes work in the normal way Negative indexes are described...
JAVA PROGRAMMING Is there a way I can use a method to place a user input...
JAVA PROGRAMMING Is there a way I can use a method to place a user input variable into an array? Then call the same method to print the array? I'm new to Java programming I'm not sure how to continue. For example: import java.util.Scanner; public class PartayScanner { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter pokemon 1:"); String pokemon1 = scan.nextLine(); System.out.println("Enter pokemon 2:"); String pokemon2 = scan.nextLine(); System.out.println("Enter pokemon 3:"); String pokemon3 = scan.nextLine();...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT