Results 1 to 7 of 7
  1. #1
    hitmen is offline Member
    Join Date
    Oct 2008
    Posts
    58
    Rep Power
    0

    Default 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.

  2. #2
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default

    Quote Originally Posted by hitmen View Post
    Firstly, how does one use a scanner class to input a character
    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 array
    Check how to use for loops. A good place to start is the Java tutorials on Sun's site. Where did you get that code from? You just made it up yourself?
    Last edited by ojn; 10-20-2008 at 04:41 PM.

  3. #3
    hitmen is offline Member
    Join Date
    Oct 2008
    Posts
    58
    Rep Power
    0

    Default

    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.

  4. #4
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default

    Quote Originally Posted by hitmen View Post
    I know that charAt is for string only. My textbook does not state anything about inputting a character.
    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.
    They're called two-dimensional or multi-dimensional arrays. You'll find a lot of examples on the web. But first, read the basics about for loops, because yours if far from working, which you would realize if you had read books/tutorials more carefully.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default

    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?

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default 25 vs 26

    You're comment is wrong... you will have 0-25 which is 26 numbers.
    What are the errors you are seeing?
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Hint...

    Hint: charAt() is NOT a scanner method.
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •