Encoder - Possibility Of Shift Being Larger Than Alphabet Array Length

Apr 20, 2015

I have an encoder that will shift the character of a string X places. Im trying to account for the possibility of the shift being larger than alphabet array length. I've come up with the following, but I still get an ArrayIndexOutOfBounds Error and it never gets past the if statement.

private String encryption(char charArrayElement) {
String [] alphabet = {"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"};
String str = String.valueOf(charArrayElement);

[Code] ....

View Replies


ADVERTISEMENT

How To Make Shift Encoder / Decoder

Oct 16, 2014

I am working on a project where we need to make a shift encoder/decoder. Right now I am working on my prepareString method, and I have no way of testing it yet. I was just wondering if I wrote it correctly. It should pull in the user entered string and check if each character is a letter, and remove all that are not. Then it should turn all the letters to upper case. Based on that does this look right?

private String prepareString(String plainText)
{
int strLength = plainText.length();
for(int i = 0; i < strLength; i++)
{
char c1 = plainText.charAt(i);
boolean isLetter = Character.isAlphabetic(c1);
if(isLetter == false)

[Code]...

View Replies View Related

Program That Continuously Asks For Alphabet Letter And Stops When Non-Alphabet Letter Entered

Oct 8, 2014

Write a program that continuously asks for an alphabet letter, and stops when a non-alphabet letter is entered. Then output the number of upper case letters, lower case letters, and vowels entered ....

View Replies View Related

Read Data From File And Place Larger Of Two Numbers In Corresponding Position Of Third Array

Apr 14, 2015

I am learning about arrays in my class and my professor has a habit of throwing in code without explaining. We are doing a program called storing largest numbers where we read data from a file and place the larger of the two numbers in the corresponding position of a third array. They are in 4 by 4 format. Here is the ending code

import java.io.*;
import java.util.*;
public class prog464aStoringLargestNums
{
public static void main(String[] args)

[code]....

View Replies View Related

Encrypt Strings Present In Array To Alphabet After 2 Positions

Mar 13, 2014

I have to encrypt the strings present in an array to the alphabet after 2 positions

Example:

my name is x

should give an output

oa pcog ku z

Although i have taken an input but unable to increment the char in the array...

View Replies View Related

Shift-left Array Values - How To Assign Divisors Indexes To Start

Dec 16, 2014

I am writing a program for a game. It is between the user and a virtual player. The game starts with a pool of consecutive integers 1-100. The size of the pool is based on a random generated number at the beginning of the game. At the start, both players' scores are 0. For each turn, the player picks one number from the pool. That value is added to the player's score, the computer gets the sum of all the remaining numbers in the pool that divide evenly into the player's pick. The player's pick and its divisors are then removed from the pool.

The player should be able to play the game as many times as she wants without ending the program. Instructions should appear on the screen only once at the start of the program.

For each turn, both players' current score, the current pool of numbers, and a prompt for a number to be entered should show onscreen. I have written the code until I get to the function that updates the pool of numbers after a turn.

import java.util.Scanner;
import java.util.Random;
public class SlickPick {
public static void main (String[] args){
Scanner read = new Scanner(System.in);
int []pool = new int[100];

[Code] ....

My thinking is that I need to use the binary search to find the indexes of the divisors array and then use those indexes as the start values. I'm not sure how to assign the divisors indexes to start. Do I need an array for start? Whenever I run the program, the only value missing is 3.

//Name : poolUpdate
//Description : This function modifies the contents of the pool as a result of a turn of play.
//Parameters : The pool array, the divisors array, the size, and the user's pick.
// :
//Return :
public static void poolUpdate(int[] pool, int[] divisors, int size, int pick){
int low=0;
int high=size-1;

[Code] ....

View Replies View Related

Possibility To Use Pass By Reference Technique In Java

Aug 27, 2014

if there is a possibility to use the pass by reference technique in java like in C++.URL....

View Replies View Related

What Is The Length Of A Null Array Object

Feb 21, 2014

I tried the following and it gives me null pointer exception. I just want to verify if what is the actual value of a length of an array?

Object [] obj = null;
System.out.println("length:" + obj.length);

View Replies View Related

How To Test For Array Length Equal To Zero

Mar 15, 2015

I am working on an assignment covering exception handling and am stuck on part of the assignment. How can you test for array length = 0?

When I try something like: if (array.length == 0) on a null array, naturally I get a NullPointerException. I would try something like if (array != null) but both array length of 0 and null array are supposed to throw different expressions.

View Replies View Related

Java Length Of One Dimension From A Multidimensional Array?

Apr 8, 2014

how you can do array.length, I have an array with [][][][], and what do I do to find the length of one section?

So let's say

Java Code: int array[][] = {
{5, 5, 5, 5},
{4, 4, 4, 4},
{3, 3, 3, 3}
} mh_sh_highlight_all('java');

How do I find out the length of the {5, 5, 5, 5} which is 4. Because there are 4 place-holders.Is there a way?

View Replies View Related

Array Of Specific Length Filled With Random Numbers

Feb 15, 2015

I was inquiring about selecting random numbers from a Fibonacci array, the original post for which is here: Exiting a 'for' Loop Early. I have managed to achieve this with the following code:

System.out.println("Random numbers from the Fibonacci array");
for(int i = 0; i < limit; i++) //Limit is an 'int' of 15 & is set as the length of the Fib. array. I'm calling it for the Random array, too!!
{
Random dice = new Random();
int randomIndex = dice.nextInt(array.length); //The Fib. array was simply called 'array'!!
if (array[randomIndex] < 100)
{
System.out.print(array[randomIndex]+ " ");
}
}

When the code prints I get a random set of numbers which occur in the Fibonacci sequence preceding it. However, the actual length of this Random array also changes each time, and never more than the limit of 15 specified in the 'for' loop. What I want to try and do is print the Random array with a specific length each time. I've tried changing the conditional statement of the 'for' loop in different ways to set the Random array's length, but had no luck.

View Replies View Related

Java Binary Encoder And Decoder Program

Aug 2, 2014

I have made a Java Binary Encoder and Decoder program and, to date, this is the program I have spent the most time developing.

I have ran Alpha tests to check the functionality is correct and it appears to work well. However I am more interested in the quality of my code ,

The code can be found over at: [URL] ....

View Replies View Related

Swing/AWT/SWT :: Allow JDialog To Resize Larger But Not Smaller

May 16, 2014

Lets say the JDialog opens 5x5. The user is allowed to modify its size to be any size larger than 5x5 but is not allowed to make it smaller. Is there such a property or will this have to be regulated via code?

View Replies View Related

LibGdx / Box2D - How To Group Tiles Into One Larger Polygon

Jan 19, 2015

I am making a tile based top-down 2D RPG and am using Box2D for the physics. Since my game is tile-based, there are many tiles on each map that cannot be moved through. This results in many small individual Box2D bodies. This is obviously very inefficient and makes the game lag. Therefore I figured that combining the individual tiles' bodies into larger complex groups would be better.

The way I thought of doing it is to, first, group together tiles into groups of tiles that all share 2 vertices with at least one other tile in the group. Then, for each group I do the following. First I get all of the uncommon vertices (these should be the ones on the outside of the polygon). Then I connect all of those vertices and then remove all of the overlapping lines. This should result in only lines on the outside of the polygon. Then I sort the lines so that the first line in the sorted array shares its end point with the second line's start point, etc. Then I remove the doubled vertices and using those remaining vertices (I called them the "true vertices") I create the polygon. I know that Box2D only supports convex polygons, but with Box2DSeparator I should be able to do this, but I first want this method to actually work.

/**
* Attempts to combine the given blocks into larger bodies to improve performance.
* @param bs The created wall blocks.
* @param w The world. Used for body creation.
*/
private void makeLargeBodies(Block[][] bs, World w) {
Array<Tile> tiles = new Array<Tile>();
for(int i = 0; i < bs.length; i++) {

[Code] .....

However, this is where the first problem arises. This method is extremely slow for large maps (like 200x200 tiles). I have worked at this for very long and right now my head can't figure out how to make the loop more efficient...

Now for the next part. After that I attempt to create the bodies for the TileGroups:

//create all the groups' bodies
size = groups.size;
System.out.println(size + " groups");
for(int i = 0; i < size; i++) {
TileGroup g = groups.get(i);
System.out.println("Starting group " + i + ".");
long timeCheck = TimeUtils.millis();
g.createBody(w);
System.out.println("Group 0 took " + (TimeUtils.millis() - timeCheck) + " millis");
}

*Note that the printing is for debugging purposes*...

This method is probably not a problem; it is what is inside createBody(World) that is the issue...

public void createBody(World w) {
Array<Vector2> allVertices = new Array<Vector2>();
Array<Vector2> uncommonVertices = new Array<Vector2>();
System.out.print("Starting search for uncommon vertices. ");
long timeCheck = TimeUtils.millis();

[Code] .....

Most of the code is self-explanatory (with comments). My current issue is where I connect the uncommon vertices (see the printed statements). This method does not actually finish (I have let it run for several minutes and it does not complete). This is likely due to a large number of vertices (often around 3000 in a 60x60 map), but I cannot figure out how to make the loop more efficient... Because of this early failure I don't know if the rest of the method works, both physically and in theory.

All relevant classes (Tile, TileGroup, Line) are below:

private class Tile {
private Vector2[] vertices;
private TileGroup group;
public Tile(int x, int y) {
vertices = new Vector2[4];

[Code] ....

View Replies View Related

Encryption - Decryption Alphabet

Mar 8, 2014

I want to create a java program that can be encrypt-decrypt alphabet from characters . Which is the shifting of the alphabet is starting from the the first character to increase 4 and 5 increased in the second character, increasing 6 at the third character, and so on..

Then when one of the characters increasement is more than the ascii code of 'z', that character will decrease from the variable i from the loop. This is the output of the program that i want:

Encryption:
Plain text: "abcz"
Cipher text: "egiz"

Decryption:
Cipher text: "egiz"
Plain text: "abcz"

This is my code for now:
 
package -;
 public class - {
 public static void main(String[] args) {
  String enkripsi = "abcz".toLowerCase();
String dekripsi = "egiz".toLowerCase();

[Code] ....

What's wrong with my code? It won't work. Specially in the decryption.

View Replies View Related

Rotate Left Bitwise Shift?

May 13, 2014

I'm trying to replicate the rol(rotate left) instruction in assembly though can only get as far as shifting the bits with '<<' or doing Long.rotateLeft(var, 5). Both of these method don't wrap around the bits as the rol instruction does.

View Replies View Related

Encoding A Message Using Caesar Shift

Feb 9, 2014

I have an assignment, similar to ones of seen in the past. The assignment is to take a users text input and to encrypt it using 3 different types of encryptions: Caesar, Transpose, and Reverser. The professor gave us the bulk of the code, and more specifically how to tokenize and shift the letters using Caeser shift. The problem im coming across is that it is not showing anything past the users input. After running it, it just stays there running without showing anything.

Cipher:

package cipher;
import java.util.Scanner;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
public abstract class Cipher {
public String message;
StringBuilder encrypted_message, decrypted_message;

[Code] ....

The constants have their own separate class, and they appear to work fine. I know that the Transpose and Reverser are incomplete, hence them commented out. But if i cant finish with Caeser first, it wont work at all.

View Replies View Related

Letters Of A String That Occur From Second Half Of Alphabet

Feb 11, 2014

Write a method named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet (that is, have values of 'n' through 'z' inclusive). Compare case-insensitively, such that uppercase values of 'N' through 'Z' also count. For example, the call secondHalfLetters("ruminates") should return 5 because the 'r', 'u', 'n', 't', and 's' come from the second half of the alphabet. You may assume that every character in the string is a letter.

View Replies View Related

How To Create A New Line Feed Character In SHIFT JIS File

Aug 29, 2014

NewLine.PNG

I need creating the end of line character on line 2 of the attached image.

When I try with

and

I get the end of line symbol on line 1. I tried converting ASCII 10 to a character and putting that in the file, but I still get the end of line symbol on line one.

I'm using Sakura as the text editor.

View Replies View Related

Build Up Alphabet Character By Character

Mar 9, 2014

I am trying to build up the alphabet character by character. Like:

a
ab
abc
abcd

Well as of now I can only print out the alphabet with my loop like abcdefg...z.. So here is the code I am trying to use:

public void loop4() {
char alph = 'a';
while(alph <= 'z') {
System.out.println(alph);
alph++; 
}
}

View Replies View Related

EJB / EE :: Is There A Limit For Length Of Get URL Request?

Oct 17, 2014

I want to know is there a limit for length of get url request? if if what is the max length.

View Replies View Related

Generate Random List Length?

Apr 16, 2015

I have my code which will generate a random string using an ArrayList. However, I aso want to have it generate them in random lengths, not just using all the chars and numbers.

public static void main(String[] args) {
String[] CHARS = {"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","1","2",
"3","4","5","6","7","8","9","0"};
List<String> pass = Arrays.asList(CHARS);
Collections.shuffle(pass);
for (String chars : pass) {
System.out.print(chars);
}
}

View Replies View Related

Count Length Of Each Word In A String

Aug 5, 2014

I am looking for a way to create a method with the initial state in while loop, which will count the length of each word in a string using I want the output to be something along the lines of:

hello world how are you
There are 0 words of length 0
There are 0 words of length 1
There are 0 words of length 2
There are 3 words of length 3
There are 0 words of length 4
There are 2 words of length 5

This is my code so far it sort of does the job but not the way i want it too

import java.util.Scanner;
import java.util.StringTokenizer;
public class Brown_Matthew_13117002{
public static int count(String s, int len){
int result=0;
StringTokenizer st=new StringTokenizer(s,"[ ,;]");

[Code] ....

The output would end up being :

hello
There are 0 words of length 0
world
There are 0 words of length 1
how
There are 0 words of length 2
are
There are 3 words of length 3
you
There are 0 words of length 4

View Replies View Related

Int Declarations - Assigning Length And Width

Mar 19, 2015

What is happening in below mentioned java code. Why in method insert, int l, int w is declaring & it is assigning to length & width.

class Rectangle{
int length;
int width;
void insert(int l,int w){
length=l;
width=w;

[Code] ....

View Replies View Related

Finding String Length Without Variables

Oct 14, 2014

The problem asks me to write an expression whose value is the number of characters in a specific string. Normally, it would be a simple task of using the String.length() method, but that is not allowed. In fact, no variable declaration is allowed (it's a MyProgrammingLab assignment, if any are familiar).

Simply put, if I have a String "This is a sample string." is it possible to find the length without assigning it to anything?

In other words, the code must be able to go into the parentheses of System.out.println( ); and correctly print the length of said string.

The answer, for those curious:

System.out.println("This is a sample string.".length());

I didn't know the .length() method could be called on a literal. Now if only I could find out how to close this thread...

View Replies View Related

Count The Length Of Each Word In A String

Jul 31, 2014

I am looking for a way to create a method with the initial state in while loop, which will count the length of each word in a string using I want the output to be something along the lines of:

hello world how are you
There are 0 words of length 0
There are 0 words of length 1
There are 0 words of length 2
There are 3 words of length 3
There are 0 words of length 4
There are 2 words of length 5

ithis is my code so far it sort of does the job but not the way i want it too

import java.util.Scanner;
import java.util.StringTokenizer;
public class Brown_Matthew_13117002{

[Code].....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved