Java 101 - Method Calls

Discussion in 'Java' started by Kasu Nai, Jul 2, 2003.

  1. Kasu Nai

    Kasu Nai Guest

    I have a very simple question. I'm stuck at one point and have no
    idea how to do this. I've tried so many things.

    I have an array (type char). I need to populate the last row
    (containing 10 columns) in this array with some values. Unfortunately
    the values are returned from a method as an integer.

    Example:

    for (col =0; col <10; col++)

    Answers[lastrow][column] = SummarizeTestScores(col);

    //Where Answers is defined as char array with 14 Rows x 10 Columns

    //Where SummarizeTestScores RETURNS a value which is an integer (i.e.
    number of correct answers per question...7 answered question 1
    correct; 5 answered question 2 correct, etc..).

    I keep getting "loss of precision" error. Please provide any input
    you may have.

    Thanks!
    Kasu
     
    Kasu Nai, Jul 2, 2003
    #1
    1. Advertising

  2. Kasu Nai

    Doug Pardee Guest

    (Kasu Nai) wrote:
    > I have an array (type char). I need to populate the last row
    > (containing 10 columns) in this array with some values. Unfortunately
    > the values are returned from a method as an integer.


    You seem to have something wrong, then.

    A "char" in Java is something very different from a "Char" in C or
    C++. A Java char is a unicode value representing a printable character
    in any of the written languages supported by unicode.

    Perhaps you meant to have a "byte" array? A Java "byte" is essentially
    the same as a "signed char" in C or C++: an integer in the range of
    -128 to +127.

    Or, if you need more bits, you can have a "short" array. For most
    cases, though, you can simply get by with an "int" array.

    > I keep getting "loss of precision" error. Please provide any input
    > you may have.


    You will get "loss of precision" whenever you stuff an int into a
    smaller data type. You can get around that by casting, which tells the
    compiler that you realize that you're losing precision and that you
    don't care.
     
    Doug Pardee, Jul 2, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Honne Gowda A
    Replies:
    2
    Views:
    907
    Karl Heinz Buchegger
    Oct 31, 2003
  2. andy6
    Replies:
    2
    Views:
    786
    andy6 via DotNetMonster.com
    Jun 9, 2006
  3. John Smith
    Replies:
    28
    Views:
    7,225
    Mike Schilling
    May 20, 2009
  4. Steve Drach
    Replies:
    3
    Views:
    225
    Thomas E Enebo
    Jun 20, 2004
  5. Michael Tan
    Replies:
    32
    Views:
    1,054
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page