Article View: aus.computers.java
Article #1190converting integers
From: Knowledge
Date: Wed, 07 Jul 1999 00:00
Date: Wed, 07 Jul 1999 00:00
60 lines
2358 bytes
2358 bytes
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:
<Kerg3.109$QF3.14392@nsw.nnrp.telstra.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,712db274a2126081,start X-Google-Attributes: gid10d6db,public From: "Knowledge" <don'tsend@email.com.au> Subject: converting integers Date: 1999/07/07 Message-ID: <Kerg3.109$QF3.14392@nsw.nnrp.telstra.net> X-Deja-AN: 497817351 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Complaints-To: abuse@telstra.net X-Trace: nsw.nnrp.telstra.net 931282986 203.58.80.244 (Wed, 07 Jul 1999 03:43:06 EST) Organization: Customer of Telstra Big Pond Direct X-MSMail-Priority: Normal NNTP-Posting-Date: Wed, 07 Jul 1999 03:43:06 EST Newsgroups: aus.computers.java