/* 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);
}
}
issue with Cipher problem
Page 1 of 11 Replies - 538 Views - Last Post: 30 October 2010 - 01:26 PM
#1
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
Replies To: issue with Cipher problem
#2
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)
http://download.orac...l#setCharAt(int,%20char)
Page 1 of 1

New Topic/Question
Reply



MultiQuote


|