Please excuse me if this question is really obvious but i’ve tried everything.
I am trying to make a calculator that calculates the percentage of a number.
But it keeps outputting a 0 for the outputs when I use this code :
import java.io.*;
class pCalc {
public static void main(String args[])
{
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream) ;
System.out.println("Hello...");
try {
System.out.println("Please Enter In The Percentage You Want To Find (e.g 25): ");
String rpercent = bufRead.readLine();
System.out.println("Please Enter In The Number You Wish To Find The Percentage Of (e.g 200): ");
String rnumber = bufRead.readLine();
int repercent = Integer.parseInt(rpercent);
int number = Integer.parseInt(rnumber);
int percent = repercent / 100;
int awnswer = number * percent ;
System.out.println("Percent is: " + percent);
System.out.println("Awnswer is: " + awnswer);
}
catch (IOException err) {
System.out.println("Error reading line");
}
catch(NumberFormatException err) {
System.out.println("Error Converting Number");
}
}
}
intis natural number (or it’s negative… blah,intis Integer), it can’t be anything between 0 or 1. You must usefloatordoubleif you want to see something like0,25