🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
3 messages
3 total messages Started by Knowledge Wed, 07 Jul 1999 00:00
converting integers
#1190
Author: Knowledge
Date: Wed, 07 Jul 1999 00:00
60 lines
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 (" ");
    }
  }
}
Re: converting integers
#1191
Author: Java Lover
Date: Wed, 07 Jul 1999 00:00
76 lines
2702 bytes
Hi I think you have solved your problem now, cya.


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 (" ");
>     }
>   }
> }
>
>
>
>
>
>
>
>
Re: converting integers
#1192
Author: boyick
Date: Wed, 07 Jul 1999 00:00
209 lines
6037 bytes
I compiled the code and it works

just declare your variables as doubles and
A_Invest   =  Double.parseDouble(initString)

should work



import java.io.*;

 public class Investment {

   public static void main (String[] args)
       throws IOException
   {

     BufferedReader stdin   =   new BufferedReader
        (new InputStreamReader (System.in));


     String initString;
     double A_Invest;
     int N_Years;
     double Interest_Rate;
     double Value;
     int j;

     System.out.print ("Enter the amount to invest: ");
     initString      =   stdin.readLine();
     A_Invest   =  Double.parseDouble(initString) ;
     System.out.print ("Enter the amount to invest: " +  A_Invest );
     System.out.print (" ");

     System.out.print ("Enter the Interest Rate:");
     initString    =   stdin.readLine();
     Interest_Rate   = Double.parseDouble(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 (" ");
    }
  }
}

----- Original Message -----
From: Knowledge <don'tsend@email.com.au>
Newsgroups: aus.computers.java
Sent: Wednesday, July 07, 1999 3:34 AM
Subject: converting integers


> 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 (" ");
>     }
>   }
> }
>
>
>
>
>
>
>
>

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 (" ");
>     }
>   }
> }
>
>
>
>
>
>
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads