String Encode / Decode Method
Apr 4, 2014
I was asked to write program in Java, that should code and encode some String in following way:
i) coding : "rrryyyyyaaaa" -> "r3y5a4"
ii) encoding: "r3y5a4" -> "rrryyyyyaaaa"
The code works fine, but I forgot the name of this coding method.
View Replies
ADVERTISEMENT
Feb 13, 2014
how to decode a .jar file to view its methods and later encode it. i wanted to write the program in java instead of using winzip
View Replies
View Related
Nov 1, 2014
I have been assigned to make a program that encodes and decodes a given message with the given key (spaced numbers, for example: 3 1 7 4 2 5). I'll post the code for all the classes that I am using below.
QueueInterface:
import java.util.*;
public interface QueueInterface<T>
{
T dequeue() throws QueueUnderflowException;
boolean isEmpty();
[Code] ....
Ok, so the classes to focus on are these:
CircularLinkedUnbndQueue
CircularLinkedQueueITD
Encoder
Decoder
EncodeDecodeConsole
EncodeDecodeITD
Because those are the ones I had to write myself, the others were given to us to use. As far as these classes go, they work fine without causing any errors from the input I give. For example if I enter a message and a key, it correctly encodes and decodes the message with the given key. What I'd like for you fine programmers to do is give feedback on those 6 classes. Like, suggestions on how to make them better or more efficient, neater, changing any of the methods to make them more efficient or prevent any errors beforehand, etc.
View Replies
View Related
Mar 30, 2015
I've a problem in encoding a URL string.
I know to encode a string we use,
URLEncoder.encode(stringname,"UTF-8");
But when I use this I'm getting an error telling that the encode method will accept only 1 String argument.
View Replies
View Related
Apr 15, 2014
So I have this file in which has a few sentences on a single line. What I need to be able to do is read the file and then take each word and create a token out of it. Then what it does is it selects the first letter of every 5th word, uppercase it, and then allow me to use append it via a stringbuffer object to create a word out of it.
I know I'll need to use a string tokenizer but I'm not sure how to do so in a way that makes each word separate and how to tell it to only hit the 1st letter of every 5th word.
Here's what I've come up with so far, but I'm currently at a loss at what to do and my textbook/documentation is just not working.
Java Code:
String line; // The line we read from the file.
char letter; // The first letter of each 5th word.
String sw; // The completed string.
public static void main (String [] args)throws IOException {
[Code] ....
View Replies
View Related
Oct 30, 2014
I have a driver and a main program. How would I go along with calling the encode method to the driver class that I made so I can have the user inputs affected by the encode method?
Java Code:
public class ShiftEncoderDecoder
{
private int shift;
public ShiftEncoderDecoder(int shift)
{
setShift(shift);
}
public int getShift()
[Code] ....
View Replies
View Related
Nov 7, 2014
So it is the question: This program implements a simple "decoder ring". It will prompt the user for a message to decode and decode the message based on the following substitution rules:
ABCDEFGHIJKLMNOPQRSTUVWXYZ will map to
ZEBRASCDFGHIJKLMNOPQTUVWXY
abcdefghijklmnopqrstuvwxyz will also map to
ZEBRASCDFGHIJKLMNOPQTUVWXY
any other characters (like space, punctuation, will map to themselves)
so if it sees an 'A' (or an 'a'), it will map to 'Z', etc... All i could think of is this but can't figure out the rest.
import java.util.Scanner;
public class DecoderRing
{
public static void main(String[] args)
{
String1[] = 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z';
String2[] = 'Z','E','B','R','A','S','C','D','F','G','H','I','J','K','L','M','N','O','P','Q','T','U','V','W','X','Y';
}
}
Not sure, what things are necessary such as switch statements or if and else or for loops and such...
View Replies
View Related
Apr 21, 2015
Im trying to HTML/JavaScript ecode the getmessage calls in the code listed below. The code below is a snippit from a program which is used to handle a failed authentication attempt.
if(logger.isDebugEnabled())
logger.debug("Authentication Failure: " + exception.getMessage());
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authentication Failed: " + exception.getMessage());
View Replies
View Related
Nov 7, 2014
How can I write a method that takes a string with duplicates letters and returns the same string which does not contain duplicates. For example, if you pass it radar, it will return rad. Also i would like to know how can I Write a method that takes as parameters the secret word and the good guesses and returns a string that is the secretword but has dashes in the places where the player has not yet guessed that letter. For example, if the secret word is radar and the player has already guessed the good guesses letters r and d, the method will return r-d-r.
View Replies
View Related
Sep 27, 2014
I am currently trying to make a calculator in Java. I want to use the String split method to tokenize the string of characters inputted. I thought I was using the String split method wrongly, because I had surrounded the characters I wanted to delimit with square brackets. However, when I removed the square brackets, the code threw an exception when I pressed the equal button. The exception was a PatternSyntaxException exception. Am I using the String split method wrongly? And why is the exception thrown? Here is my code:
import javax.swing.*;//import the packages needed for gui
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.List;
import static java.lang.Math.*;
public class CalculatorCopy {
public static void main(String[] args) {
[Code] .....
View Replies
View Related
Dec 16, 2014
i am trying to write a class method which will take in a string and returns a string which is the reversed version of that string. it compiles fine but when i try to run it it states Main method not found in class StringReverse,please define the main method as public static void main(String[]args). I am new to java and cannot figure out
import javax.swing.JOptionPane;
public class StringReverse {
public String reverseString(String str){
JOptionPane.showInputDialog(null,"Please enter word");
char c = str.charAt(str.length()-1);
if(str.length() == 1) return Character.toString(c);
return c + reverseString(str.substring(0,str.length()-1));}}
View Replies
View Related
Mar 18, 2014
Code a Java method that accepts a String array and a String. The method should return true if the string can be found as an element of the array and false otherwise. Test your method by calling it from the main method which supplies its two parameters (no user input required). Use an array initialiser list to initialise the array you pass. Test thoroughly.
public class test {
public static void main(String[] args) {
Printhelloworld();
String[] verbs = {"go", "do", "some", "homework"};
printArrays(verbs);
[Code] .....
View Replies
View Related
Sep 21, 2014
So I'm creating a class which when given three inputs uses them as sides of a triangle and tells ther user what type of triangle it is, or if the input is invalid, tells them why it is invalid. I'm readin the input as a string and then trying to split it into a string array, from there checking to see if it has 3 elements.. in which the data is good at that point, and then converting them to ints and checking to see if they're negative ansd finally checking to see if they can work as sides of a triangle ie a+b >c, a+c >b , b+c >a.
I'm trying to split it into an array of strings but am getting an error, and can't seem to figure out why as this should be working from what I've read of the string.split method online.
import java.util.*;
public class TriangleTest{
private int sideA;
private int sideB;
private int sideC;
public static void main(String[] args){
TriangleTest triangle = new TriangleTest("3 4 5");
[Code] ....
The output reads [Ljava.lang.String;@15db9742
View Replies
View Related
Oct 20, 2014
The only problem I am having is I cannot get my string plainText to go through the encode and prepareString methods.
Is there something in my methods that is wrong, or is it the way that I am calling them?
What is happening is if I enter "this is a test" as a plainText I am getting the samething back with no changes.
View Replies
View Related
Aug 7, 2014
I am getting incombatable types, I do not know why I am getting them..why I am getting the error?
The Error I am getting:
stringSort.java:26: error: incompatible types
if(myArray[j].compareToIgnoreCase(myArray[i].toString())){
^
required: boolean
found: int
*/
[code]....
View Replies
View Related
Oct 23, 2014
I need to get the string encodedString from the method encode able to be used in the decode method.
Java Code:
public String encode(String plainText) {
int prepareString;
int shiftChar;
String preparedString2 = prepareString(plainText);
String encodedString = "";
for(int c = 0 ; c < preparedString2.length();c++)
[Code] ....
View Replies
View Related
Oct 15, 2014
I understand that the intern() method is to be used when you create Strings using the new operator and you want the 2 strings to be the same object. But in that case, why can't we just enclose the 2 strings in double quotes instead of using the new operator
View Replies
View Related
Jan 14, 2014
How do I make a method that can seperate parts of a String. The String is [name,aid]... example [John,5],
I want to remove [ , and ] from the String... How can I do this?
This is what i've done this far:
static public String splitta(String tf)
{
String part1 = "";
String part2 = "";
String part11 = "";
String part22 = "";
String part111 = "";
String part222 = "";
String[] parts = new String[2];
[Code] ....
This dosn't work, it wont compile... It states the following:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at testprojekt.Validering.splitta(Validering.java:130)
View Replies
View Related
Nov 21, 2014
I have to take a user's input and count the number of vowels in a String. If I start with a lowercase vowel it gets counted, but if I start with an uppercase or different letter I get nothing. Either way, I can not get the counter to go higher than 1.
import java.util.Scanner;
public class countVowels
{
public static void main(String[] args)
{
Scanner kb=new Scanner(System.in);
System.out.println("Enter a sequence of letters:");
String letters=kb.next();
[code]...
View Replies
View Related
Oct 19, 2014
In this exercise, create a program that asks a user for a phrase, then returns the phrase with the words in reverse order. Use the String class's .split() method for this.
Example input
The rain in Spain falls mainly on the plain
Example output
plain the on mainly falls Spain in rain The
While I understand the assignment, nowhere in the text is it covered how to reverse the order of the words in the string. I understand using the .split method, but not for this exercise.
Here is my code so far.
import java.util.*;
/**
* Java class SplitString
* This program asks for a phrase, and the code allows the phase to return in reverse order.
*/
public class SplitString {
public static void main (String[] args){
//set phrase input and mixed which will be the result
[Code] ....
As you can see, I have been googling this method and have come up nearly empty. My text does not cover the .reverse() method. The only thing it covers with .split() is how to split a string. I also tried StringBuilder with no success.
View Replies
View Related
May 22, 2014
I am little confused about String creation in java.
Doubt 1: How String objects assigned to Pool area:
1. String s="in pool";
2. String s1= new String("not in pool");
How many objects created in statement 1 and 2. According to recent discussion with my colleague, one object created in String pool in case 1. And in case 2, two objects are created, one as literal goes to String pool and other with new() opr goes to Heap.
If above is correct, Ain't we wasting double memory for same object ? Really need clear understanding on this
Doubt 2: How does intern() work: Please see if my below explanation is correct
1. If String literal is already present in String pool , and i create a same string with new operator, reference to object is changed to pool area.
2. If String object is created using new operator and intern is called on it. If same string object is not present in the String Pool, Its moved to String pool and reference to this in Pool is returned.
View Replies
View Related
Nov 9, 2014
How would I go about and make an enum, that has Strings and Methods?I want to make a class called GraphicalEffects, this class and be instanstiated and it has a method to apply graphicalEffects AS methods or some type of references to methods in an ArrayList.
View Replies
View Related
Feb 17, 2014
I have the following code which always gives me java heap space error because of line number 65 due to string buffer append method in this line, I don't know why?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import samy.*;
import java.util.Scanner;
public class InfixToPostfix {
OrderedList list = new OrderedList();
Scanner input = new Scanner(System.in);
public StringBuffer postfix = new StringBuffer();
[Code] .....
View Replies
View Related
Jul 11, 2014
I'm having an issue with figuring out how to structure and call a method using a string prompt. My prof has given us specific methods to create, and the one I'm having issues with is blic static double getOperand(String prompt). What I have currently is this:
public static double getOperand(String operand1, String operand2){
Scanner input = new Scanner(System.in);
System.out.println("What is the first operand?");
operand1 = input.toString();
System.out.println("What is the second operand?");
operand2 = input.toString();
return operand1, operand2;
}
which is obviously not working. When I asked my prof he sent me this, "The String paramater in the getOperand() method is intended to have the prompt value that is passed to it. Within the method, the prompt is then displayed, what the prompt is asking for is input, and then returned to the method call.For example, if the method is public double getOperand(String prompt) within the method you would display the prompt, as in System. out. println(prompt), use the Scanner class to create an object, perhaps called input, and then use the input object to get the value asked for by the prompt. Once you have that value, which in this example would be a double, then return the value to the method that called it.
The call could be something like this: double value = getOperand("What is the first operand?");". But that only works a little. Clearly I'm missing something and no matter what I google, or how many times I read the chapter, I am just not getting this. Everything else up to this point has been easy. and I can create regular methods just fine, the menu method works, but I can't figure out this string method and all the rest build off this method.
View Replies
View Related
Oct 6, 2014
One interviewer has asked me one question that why main() method has argument "String[] arg".What is reason behind this ??I am unable to explain it because i never think about it ..
View Replies
View Related
Feb 12, 2015
I want to make a private method that will change the value of a instance variable like this:
String bla = "bla bla bla";
private void changeString (String x) { x = "eee";}
changeString(bla);
Now value of the variable bla should be "eee" but its not, it is stil "bla bla bla".
View Replies
View Related