Results 1 to 7 of 7
Thread: Elementary Quesions
- 10-20-2008, 04:31 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 58
- Rep Power
- 0
Elementary Quesions
Firstly, how does one use a scanner class to input a character
System.out.println("Enter the character you want");
Scanner sc = new Scanner (System.in);
char character;
character = sc.charAt(0); //????? wrong
Secondly, what is wrong with these few lines of code. I want to load my array
public class Ciphers {
//instance variable
private int lookuptable[][] = new int [26][26];
for (row=0; row < 26 ; row++ ){
for (col=0; col < 26; col++){ // load table
lookuptable = lookuptable[row][col];
}
}
}
Each row should have the numbers 0 to 26.
Thanks.
- 10-20-2008, 04:37 PM #2
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
Check the API. Does charAt() do what you wish? If not, what other methods can you use? Come back with your findings.
Secondly, what is wrong with these few lines of code. I want to load my arrayLast edited by ojn; 10-20-2008 at 04:41 PM.
- 10-20-2008, 04:48 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 58
- Rep Power
- 0
I know that charAt is for string only. My textbook does not state anything about inputting a character.
For my array I know my last line is wrong but I just cant get it.
- 10-20-2008, 05:12 PM #4
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
You want to get a char input? You find anything in the Scanner class that does this? No? Ok, now what? Oh, there are methods that return a String. Let's try one of those (you have to figure out which one, either by reading the description or via trial and error) and use that String to get the first char (use charAt).
For my array I know my last line is wrong but I just cant get it.
- 10-20-2008, 05:15 PM #5
Do you get an error message when you compile your code? What does it say?
What does the API doc for the Scanner class say about reading in a char? Do any of its methods return a char? It will return a lot of different types of data. What about char?
What do you mean by a 'character' vs a char? Is that a String of length 1?
- 10-20-2008, 05:25 PM #6
25 vs 26
You're comment is wrong... you will have 0-25 which is 26 numbers.
What are the errors you are seeing?
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 10-21-2008, 12:23 AM #7
Bookmarks