Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java 101 - Method Calls

Reply
Thread Tools

Java 101 - Method Calls

 
 
Kasu Nai
Guest
Posts: n/a
 
      07-02-2003
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
 
Reply With Quote
 
 
 
 
Doug Pardee
Guest
Posts: n/a
 
      07-02-2003
(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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Poll: Is a Java Method an Instance of the Java Classjava.lang.reflect.Method? Please reply with YES or NO. Paka Small Java 15 02-07-2012 07:04 PM
org.apache.axis.AxisFault.makeFault(AxisFault.java:101) John Smith Java 28 05-20-2009 07:14 PM
ods calls business object then method calls ta with output params andy6 ASP .Net 2 06-09-2006 01:54 AM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
JRuby: How does one keep Java objects as Java objects so they can be used in method calls? Steve Drach Ruby 3 06-19-2004 11:25 PM



Advertisments