I'm very new to the Java language, and in one of my school assignments, they want us to take in a simple text file that contains a line of text and index it (so that it can be used as a decoder for a secret message). I already know how to read the file and get that line of text into the program, but how do I index each character in the line of text and assign each character a value starting at 0 and ending at the length of the line of text? Here is what I have so far (*Note: I was trying different stuff with the code in the for loop, so I'm not sure if I'm on the right track or not):
import java.util.*;
import java.io.*;
public class Decoder
{
public static void main(String[] args) throws IOException
{
Scaer keyboard = new Scaer(System.in);
String fileName;
System.out.println("Please enter the name of a file to be decoded: ");
fileName = keyboard.nextLine();
File testFile = new File(fileName);
Scaer inputFile = new Scaer(testFile);
String keyPhrase = inputFile.nextLine();
for(int i = 0; i < keyPhrase.length(); i++)
{
char letter = keyPhrase.charAt(i);
int num = (int)letter;
System.out.println(num);
}
}
}
