Search code examples
javadatainputstream

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

Solution

  • try using BufferedReader

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

    tempString = reader.readLine();