简体   繁体   中英

Need Help in taking Input from DataInputStream in java

Here's my code :

import java.io.*;

class InterestCalcs {

    public static void main(String arg[]) {
        Float prinAmount = new Float(0);
        Float ROI = new Float(0);
        DataInputStream in = new DataInputStream(System.in);
        String tempString;
        int noOfYears;
        System.out.println("Enter Amount :");
        System.out.flush();
        tempString = in .readLine();
        prinAmount = Float.valueOf(tempString);
        System.out.println("Enter ROI:");
        System.out.flush();
        tempString = in .readLine();
        ROI = Float.valueOf(tempString);
        System.out.flush();
        tempString = in .readLine();
        noOfYears = Integer.parseInt(tempString);
        float interestTotal = ROIprinAmountnoOfYears;
        System.out.println("The total interest is " + interestTotal);
    }
}

try using BufferedReader

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

tempString = reader.readLine();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM