String to Char Array in Java 2011View more random threads:
- JSP came when the Servlets , Need for JSP With servlets,SF...
- How static class variables get initialized
- TableModelListener ERROR in Java 2011
- Deployment Flow / Process from netBean IDE to tomcat...
- Java as Object Oriented programming languge 2011
- what are the latest updates for Java May 2011
- How find the data in ArrayList? 2011-12
- What is the difference between Java and Java 2EE
- JAVA Error 1723. There is a problem with this Windows...
- New development in java 2011
import java.util.*;
import java.io.*;
public class Test2
{
public static void main (String[] args) throws IOException
{
Scanner input = new Scanner(new FileReader("cipher2.in"));
String cipherText;
String cipherDirection;
String cipherType;
int cipherKey;
cipherKey = input.nextInt();
cipherDirection = input.next();
cipherType = input.next();
cipherText = input.next();
encrypt(cipherText, cipherKey);
}
public static void encrypt(String cipherText, int cipherKey)
{
int letterPosition;
int arrayPosition;
char[] cipherCode = new char[cipherText.length()];
letterPosition = cipherKey;
for (arrayPosition = 0; arrayPosition == cipherText.length(); arrayPosition++, letterPosition++)
{
if (cipherKey > 0 && letterPosition == cipherText.length())
{
for (letterPosition = 0; letterPosition == cipherKey; letterPosition++, arrayPosition++)
{
cipherCode[arrayPosition] = cipherText.charAt(letterPosition);
}
}
else
{
cipherCode[arrayPosition] = cipherText.charAt(letterPosition);
System.out.print(cipherCode[arrayPosition]);
}
}
System.out.print("Cipher Code: ");
for(int i = 0; i < cipherText.length(); i++)
{
System.out.print(cipherCode[i]);
}
System.out.println("\nCipher Text: " + cipherText);
System.out.println("Cipher Key: " + cipherKey);
}
}
Sponsored Links
There are currently 1 users browsing this thread. (0 members and 1 guests)