1 Replies - 538 Views - Last Post: 30 October 2010 - 01:26 PM Rate Topic: -----

#1 Odaym   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 06-January 10

issue with Cipher problem

Posted 30 October 2010 - 01:15 PM

Hello, the following code is supposed to get 5 characters from the keyboard, and a shift amount. go through the array in which the characters will be placed, and for each cell, replace its letter value with (itself + 3) (shift 3 letters after the original letter, and put the new letter instead of the original)..But i dont yet know how to receive letter by letter into an array. I know Scanner.next() for example, to get a whole String, but with the string i cannot traverse..or at least i think so. please help, thank you very much

/*	Oday Maleh
	Sat 30 Oct 2010 10:45:45 PM EEST 	*/

import java.util.Scanner;

public class Cipher
{
	public static void main (String args[])
	{
		Scanner s = new Scanner (System.in);
		Character array[] = new Character[5];

		for (int i = 0; i < array.length; i++)
			array[i] = //HERE IS WHERE I DONT KNOW WHAT TO DO			
	
		System.out.print ("Enter the shift value : ");
		int shift = s.nextInt();

		for (int i = 0; i < array.length; i++)
			array[i] = array[i] + 3; //HERE ALSO, I THOUGHT I COULD DO "INT N = 'C'", SO WHY CANT I DO THIS ONE ALSO?

		String output = "";

		for (int i = 0; i < array.length; i++)
			output += array[i];

		System.out.print (output);
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: issue with Cipher problem

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: issue with Cipher problem

Posted 30 October 2010 - 01:26 PM

You can use a StringBuilder and set the character appropriately

http://download.orac...l#setCharAt(int,%20char)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1