Java Floating point number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.