Java 101 - Method Calls

K

Kasu Nai

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
 
D

Doug Pardee

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top