-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decimalcomparsion.java
32 lines (25 loc) · 1.01 KB
/
Decimalcomparsion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
public class Decimalcomparsion {
public Decimalcomparsion() {
}
public static void main(String[] args) {
//vishal
//taking input of float type from user
Scanner sc = new Scanner(System.in);
System.out.println("Enter the double value");
double num = sc.nextDouble();
//changing float value to string
String doubleAsString = String.valueOf(num);
//values after decimal point
int indexOfDecimal = doubleAsString.indexOf(".");
System.out.println("Double Number: " + num);
System.out.println("Integer Part: " + doubleAsString.substring(0, indexOfDecimal));
System.out.println("Decimal Part: " + doubleAsString.substring(indexOfDecimal + 1));
//equal or not
if (doubleAsString.substring(indexOfDecimal + 1).equals(doubleAsString.substring(0, indexOfDecimal))) {
System.out.println("Equal");
} else {
System.out.println("Not Equal");
}
}
}