Article View: aus.computers.java
Article #1103Re: converting integers
From: Martin Devlin
Date: Fri, 16 Jul 1999 00:00
Date: Fri, 16 Jul 1999 00:00
90 lines
3138 bytes
3138 bytes
Howdy
I read the message about the person doing a program for their course.
Your supposed to use the Double.ValueOf() and DoubleValue() methods of
the
java.lang.integer class.
I would suggest, you (presumably)rewrite the integer.parseint method to
incorporate the
following coded example
double DecVal (String initString) {
double DecVal = double.ValueOf(initString).doublevalue();
}
This should, give you the decimal equivalent of your string.
Hope this helps
Knowledge <don'tsend@email.com.au> wrote in message
news:Kerg3.109$QF3.14392@nsw.nnrp.telstra.net...
> Hi....I am writing this program for my course. I have been mucking around
> with doubles and floats...etc. Though I have tried to set the variables to
> double, I get compile errors. I have changed Integer.parseInt (initString)
> to Double.parseDouble(initString) but this compiles an error and too
mention
> that double A_Invest; also compiles an error.
>
> What I am asking is, Can someone show me how to change the
Integer.parseInt
> (initString) so I can accept decimal input from the command line. Here is
my
> source code:-
>
>
>
>
> import java.io.*;
>
> public class Investment {
>
> public static void main (String[] args)
> throws IOException
> {
>
> BufferedReader stdin = new BufferedReader
> (new InputStreamReader (System.in));
>
>
> String initString;
> int A_Invest;
> int N_Years;
> int Interest_Rate;
> int Value;
> int j;
>
> System.out.print ("Enter the amount to invest: ");
> initString = stdin.readLine();
> A_Invest = Integer.parseInt (initString);
>
> System.out.print (" ");
>
> System.out.print ("Enter the Interest Rate:");
> initString = stdin.readLine();
> Interest_Rate = Integer.parseInt (initString);
>
> System.out.print (" ");
>
> System.out.print ("Enter the number of years: ");
> initString = stdin.readLine();
> N_Years = Integer.parseInt (initString);
>
> System.out.print (" ");
>
> Value = A_Invest * (1 + Interest_Rate) * N_Years;
>
> j = 1;
> for (int i = 0; i < N_Years; i++) {
> System.out.print ("The value of your " + j++);
> System.out.print (" Year return will be: " + Value);
> System.out.println (" ");
> }
> }
> }
>
>
>
>
>
>
>
>
Technical Details
Message-ID:
<7mnqfe$coh$1@news4.svr.pol.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<Kerg3.109$QF3.14392@nsw.nnrp.telstra.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,712db274a2126081 X-Google-Attributes: gid10d6db,public From: "Martin Devlin" <martind@myemail55.freeserve.co.uk> Subject: Re: converting integers Date: 1999/07/16 Message-ID: <7mnqfe$coh$1@news4.svr.pol.co.uk> X-Deja-AN: 501811599 References: <Kerg3.109$QF3.14392@nsw.nnrp.telstra.net> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-Complaints-To: abuse@theplanet.net X-Trace: news4.svr.pol.co.uk 932146478 13073 62.136.33.64 (16 Jul 1999 17:34:38 GMT) Organization: Customer of Planet Online X-MSMail-Priority: Normal NNTP-Posting-Date: 16 Jul 1999 17:34:38 GMT Newsgroups: aus.computers.java