Package precisenumber;
Import java.util.*;
public class Precisenumber {
public int fore;
public int after;
public void DTI (double num)//double to int
{
String numstr = double.tostring (num);
String forestr = numstr.substring (0, Numstr.indexof ("."));
String afterstr = numstr.substring (Numstr.indexof (".") + 1);
This.fore = Integer.parseint (FORESTR);
This.after = Integer.parseint (AFTERSTR);
}
Public double ITD ()//int to double
{
String numstr = This.fore + "." + This.after;
Double num = double.parsedouble (NUMSTR);
return num;
}
public void Putnum (double num) {
System.out.println ("number" + num);
}
public static void Main (string[] args) {
}
}
Package precisenumber;
Import Java.util.Scanner;
public class Text {
Private Precisenumber Num1 = new Precisenumber ();
Private Precisenumber Num2 = new Precisenumber ();
Private Precisenumber result = new Precisenumber ();
Public double Getnum () {
Scanner in = new Scanner (system.in);
Double num = in.nextdouble ();
return num;
}
public void Add (double num1, double num2) {
Num1.dti (NUM1);
Num2.dti (NUM2);
Result.fore = Num1.fore + Num2.fore;
Result.after = Num1.after + num2.after;
Double num;
num = result. ITD ();
Result.putnum (num);
}
public void subtract (double num1, double num2) {
Num1.dti (NUM1);
Num2.dti (NUM2);
Result.fore = Num1.fore-num2.fore;
Result.after = Num1.after-num2.after;
Double num;
num = result. ITD ();
Result.putnum (num);
}
public void multiplication (double num1, double num2) {
Num1.dti (NUM1);
Num2.dti (NUM2);
Result.fore = Num1.fore * Num2.fore;
Result.after = Num1.after * num2.after;
Double num;
num = result. ITD ();
Result.putnum (num);
}
public void Devide (double num1, double num2) {
Num1.dti (NUM1);
Num2.dti (NUM2);
Result.fore = Num1.fore/num2.fore;
Result.after = Num1.after/num2.after;
Double num;
num = result. ITD ();
Result.putnum (num);
}
public static void Main (string[] args) {
Text operate = new text ();
SYSTEM.OUT.PRINTLN ("Input num 1:");
Double num1 = Operate.getnum ();
SYSTEM.OUT.PRINTLN ("Input num 2:");
Double num2 = Operate.getnum ();
System.out.println ("Select operation:");
System.out.println ("1. Plus 2. Minus 3. By 4.");
Scanner in = new Scanner (system.in);
int i = In.nextint ();
switch (i) {
Case 1:
Operate.add (NUM1, num2);
Break
Case 2:
Operate.subtract (NUM1, num2);
Break
Case 3:
Operate.multiplication (NUM1, num2);
Break
Case 4:
Operate.devide (NUM1, num2);
Break
}
}
}
Java Floating point number