Sie sind auf Seite 1von 2

Ques. Write a program to read the price of an item in decimal form (like 75.

95) and print the


output in paisa (like 7595 paisa)
Ans:

First Way:

import java.io.*;
class rsTopaisa
{
public static void main(String args[])
{
double rupee, paisa;
String s;

try {
BufferedReader ob1 = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter no. of Rupees in decimal form (like 75.94): ");
System.out.flush();
s = ob1.readLine();
rupee = Double.parseDouble(s);
paisa = rupee*100.00 ;
System.out.println(rupee+" Rupees equals to "+paisa+" Paisa");
}
catch (Exception e) {
System.out.println("Error is: " + e);
}
}
}






Here output is showing in decimal form the result should be 3845 only.








Output:
Enter no. of Rupees in decimal form (like 75.94): 38.45
3845 Rupees equals to 3845.0 Paisa
Second Way:

import java.io.*;
class rsTOpaisa
{
public static void main(String args[])
{
int paisa, mantissa;
float rs, exponent;
String s;

try {
BufferedReader ob1 = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter no. of Rupees in decimal form (like 75.94): ");
System.out.flush();
s = ob1.readLine();
rs = Float.parseFloat(s);
mantissa = (int)rs;
exponent = rs-(float)mantissa;
paisa = (int)((mantissa*100) + (exponent*100));
System.out.println(rs+" Rupees equals to "+paisa+" Paisa");
}
catch (Exception e) {
System.out.println("Error is: " + e);
}
}
}






But if we enter 75.95 then output is coming as > 7594 (and this is happening just for this number)
Output:
Enter no. of Rupees in decimal form (like 75.94): 38.45
3845 Rupees equals to 3845 Paisa

Das könnte Ihnen auch gefallen