Java by API/java.lang/Double — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:40, 31 мая 2010
Содержание
- 1 Double: byteValue()
- 2 Double: compare(double d1, double d2)
- 3 Double: compareTo(Double anotherDouble)
- 4 Double: doubleValue()
- 5 Double: equals
- 6 Double: floatValue()
- 7 Double: intValue()
- 8 Double: isInfinite()
- 9 Double: isNaN()
- 10 Double.MAX_VALUE
- 11 Double.MIN_VALUE
- 12 Double.NEGATIVE_INFINITY
- 13 Double: parseDouble(String s)
- 14 Double.POSITIVE_INFINITY
- 15 Double: shortValue()
- 16 Double: toString(double d)
- 17 Double: valueOf(String stringValue)
- 18 new Double(double value)
- 19 new Double(String stringValue) "-5"
Double: byteValue()
public class Main {
public static void main(String[] args) {
Double dObj = new Double("10.50");
byte b = dObj.byteValue();
System.out.println(b);
short s = dObj.shortValue();
System.out.println(s);
int i = dObj.intValue();
System.out.println(i);
float f = dObj.floatValue();
System.out.println(f);
double d = dObj.doubleValue();
System.out.println(d);
}
}
/*
10
10
10
10.5
10.5
*/
Double: compare(double d1, double d2)
public class Main {
public static void main(String[] args) {
double d1 = 5.5;
double d2 = 5.4;
int i1 = Double.rupare(d1, d2);
if (i1 > 0) {
System.out.println(">");
} else if (i1 < 0) {
System.out.println("<");
} else {
System.out.println("=");
}
Double dObj1 = new Double("5.5");
Double dObj2 = new Double("5.4");
int i2 = dObj1.rupareTo(dObj2);
if (i2 > 0) {
System.out.println(">");
} else if (i2 < 0) {
System.out.println("<");
} else {
System.out.println("=");
}
}
}
Double: compareTo(Double anotherDouble)
public class Main {
public static void main(String[] args) {
double d1 = 5.5;
double d2 = 5.4;
int i1 = Double.rupare(d1, d2);
if (i1 > 0) {
System.out.println(">");
} else if (i1 < 0) {
System.out.println("<");
} else {
System.out.println("=");
}
Double dObj1 = new Double("5.5");
Double dObj2 = new Double("5.4");
int i2 = dObj1.rupareTo(dObj2);
if (i2 > 0) {
System.out.println(">");
} else if (i2 < 0) {
System.out.println("<");
} else {
System.out.println("=");
}
}
}
Double: doubleValue()
/*
* Output:
10.234
*/
public class MainClass {
public static void main(String args[]) {
double degrees = Double.valueOf("10.234").doubleValue();
System.out.println(degrees);
}
}
Double: equals
/*
* Output:
3.14159 = 3.14159 -> true
*
*/
public class MainClass {
public static void main(String args[]) {
Double d1 = new Double(3.14159);
Double d2 = new Double("314159E-5");
System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
}
}
Double: floatValue()
public class Main {
public static void main(String[] args) {
Double dObj = new Double("10.50");
byte b = dObj.byteValue();
System.out.println(b);
short s = dObj.shortValue();
System.out.println(s);
int i = dObj.intValue();
System.out.println(i);
float f = dObj.floatValue();
System.out.println(f);
double d = dObj.doubleValue();
System.out.println(d);
}
}
/*
10
10
10
10.5
10.5
*/
Double: intValue()
public class Main {
public static void main(String[] args) {
Double dObj = new Double("10.50");
byte b = dObj.byteValue();
System.out.println(b);
short s = dObj.shortValue();
System.out.println(s);
int i = dObj.intValue();
System.out.println(i);
float f = dObj.floatValue();
System.out.println(f);
double d = dObj.doubleValue();
System.out.println(d);
}
}
/*
10
10
10
10.5
10.5
*/
Double: isInfinite()
/*
* Output:
*
Infinity: true, false
NaN: false, true
*
*/
public class MainClass {
public static void main(String args[]) {
Double d1 = new Double(1/0.);
Double d2 = new Double(0/0.);
System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
}
}
Double: isNaN()
/*
* Output:
*
Infinity: true, false
NaN: false, true
*
*/
public class MainClass {
public static void main(String args[]) {
Double d1 = new Double(1/0.);
Double d2 = new Double(0/0.);
System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
}
}
Double.MAX_VALUE
/*
* Output:
1.7976931348623157E308
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Double.MAX_VALUE);
}
}
Double.MIN_VALUE
/*
* Output:
4.9E-324
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Double.MIN_VALUE);
}
}
Double.NEGATIVE_INFINITY
/*
* Output:
-Infinity
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Double.NEGATIVE_INFINITY);
}
}
Double: parseDouble(String s)
public class Main {
public static void main(String[] argv) throws Exception {
double d = Double.parseDouble("123.4e10");
System.out.println(d);
}
}
Double.POSITIVE_INFINITY
/*
* Output:
Infinity
*/
public class MainClass {
public static void main(String args[]) {
System.out.println(Double.POSITIVE_INFINITY);
}
}
Double: shortValue()
public class Main {
public static void main(String[] args) {
Double dObj = new Double("10.50");
byte b = dObj.byteValue();
System.out.println(b);
short s = dObj.shortValue();
System.out.println(s);
int i = dObj.intValue();
System.out.println(i);
float f = dObj.floatValue();
System.out.println(f);
double d = dObj.doubleValue();
System.out.println(d);
}
}
/*
10
10
10
10.5
10.5
*/
Double: toString(double d)
public class Main {
public static void main(String[] args) {
double d = 8.48;
String s = Double.toString(d);
}
}
Double: valueOf(String stringValue)
/*
* Output:
10.234
*/
public class MainClass {
public static void main(String args[]) {
double degrees = Double.valueOf("10.234").doubleValue();
System.out.println(degrees);
}
}
new Double(double value)
/*
* Output:
3.14159 = 3.14159 -> true
*
*/
public class MainClass {
public static void main(String args[]) {
Double d1 = new Double(3.14159);
Double d2 = new Double("314159E-5");
System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
}
}
new Double(String stringValue) "-5"
/*
* Output:
3.14159 = 3.14159 -> true
*
*/
public class MainClass {
public static void main(String args[]) {
Double d1 = new Double(3.14159);
Double d2 = new Double("314159E-5");
System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
}
}