📄 数值类型.txt
字号:
数值类型 List.1 Math.txt
数值类型 List.2 AbsValue/AbsValue.java
数值类型 List.3 MinMax/MinMax.java
数值类型 List.4 CeilFloor/CeilFloor.java
数值类型 List.5 PowerDemo/PowerDemo.java
数值类型 List.6 Remainder/Remainder.java
数值类型 List.7 Round/Round.java
数值类型 List.8 CosDemo/CosDemo.java
数值类型 List.9 RandomDemo/RandomDemo.java
数值类型 List.10 Random.txt
数值类型 List.11 RandGen/RandGen.java
数值类型 List.12 RandomBytes/RandomBytes.java
数值类型 List.13 RandomSeed/RandomSeed.java
数值类型 List.14 Boolean.txt
数值类型 List.15 BooleanDemo/BooleanDemo.java
数值类型 List.16 GetProperty/GetProperty.java
数值类型 List.17 IntCommon.txt
数值类型 List.18 Integer.txt
数值类型 List.19 ConvertInt/ConvertInt.java
数值类型 List.20 Long.txt
数值类型 List.21 Byte.txt
数值类型 List.22 Short.txt
数值类型 List.23 FloatCommon.txt
数值类型 List.24 Float.txt
数值类型 List.25 ParseFloat/ParseFloat.java
数值类型 List.26 Double.txt
--------------------------------------------------------------------------------
数值类型 List.1 Math.txt
Return to top
001: // Math class constructor
002: private Math() {}
003:
004: // Math class constants
005: public static final double E = 2.7182818284590452354;
006: public static final double PI = 3.14159265358979323846;
007:
008: // Math class methods
009: public static double sin(double a);
010: public static double cos(double a);
011: public static double tan(double a);
012: public static double asin(double a);
013: public static double acos(double a);
014: public static double atan(double a);
015: public static double toRadians(double angdeg);
016: public static double toDegrees(double angrad);
017: public static double exp(double a);
018: public static double log(double a);
019: public static double sqrt(double a);
020: public static double IEEEremainder(double f1, double f2);
021: public static double ceil(double a);
022: public static double floor(double a);
023: public static double rint(double a);
024: public static double atan2(double a, double b);
025: public static double pow(double a, double b);
026: public static int round(float a);
027: public static long round(double a);
028: public static double random();
029: public static int abs(int a);
030: public static long abs(long a);
031: public static float abs(float a);
032: public static double abs(double a);
033: public static int max(int a, int b);
034: public static long max(long a, long b);
035: public static float max(float a, float b);
036: public static double max(double a, double b);
037: public static int min(int a, int b);
038: public static long min(long a, long b);
039: public static float min(float a, float b);
040: public static double min(double a, double b);
Return to top
--------------------------------------------------------------------------------
数值类型 List.2 AbsValue/AbsValue.java
Return to top
001: class AbsValue {
002: public static void main(String args[]) {
003: int v = -100;
004: char ch = (char)Math.abs(v);
005: System.out.println("char(" + Math.abs(v) + ") = " + ch);
006: }
007: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.3 MinMax/MinMax.java
Return to top
001: class MinMax {
002: public static void main(String args[]) {
003: long v1 = 99;
004: long v2 = v1 * 2;
005: System.out.println("v1=" + v1 + " v2=" + v2);
006: System.out.println("Maximum value = " + Math.max(v1, v2));
007: System.out.println("Minimum value = " + Math.min(v1, v2));
008: }
009: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.4 CeilFloor/CeilFloor.java
Return to top
001: class CeilFloor {
002: public static void main(String args[]) {
003: double d = 10.0;
004: while (d < 11.0) {
005: System.out.println("d=" + d + " ceil(d)=" + Math.ceil(d) +
006: " floor(d)=" + Math.floor(d));
007: d += 0.1;
008: }
009: }
010: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.5 PowerDemo/PowerDemo.java
Return to top
001: class PowerDemo {
002: public static void main(String args[]) {
003: if (args.length < 2) {
004: System.out.println("Enter two values as follows:");
005: System.out.println("java PowerDemo 2 8");
006: } else {
007: try {
008: int j = Integer.parseInt(args[0]);
009: int k = Integer.parseInt(args[1]);
010: System.out.println(j + " ^^ " + k + " = " + Math.pow(j, k));
011: }
012: catch (NumberFormatException e) {
013: System.out.println("Error in argument " + e.getMessage());
014: }
015: }
016: }
017: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.6 Remainder/Remainder.java
Return to top
001: class Remainder {
002: public static void main(String args[]) {
003: double arg1 = 3.14159;
004: double arg2 = 2;
005: double result = Math.IEEEremainder(arg1, arg2);
006: System.out.println(arg1 + " / " + arg2 + " = " + result);
007: }
008: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.7 Round/Round.java
Return to top
001: class Round {
002: public static void main(String args[]) {
003: double arg = 3.14159;
004: double doubleResult = Math.rint(arg);
005: int intResult = (int)Math.round(arg);
006: long longResult = Math.round(arg);
007: System.out.println("double rint(arg) = " + doubleResult);
008: System.out.println("(int)round(arg) = " + intResult);
009: System.out.println("(long)round(arg) = " + longResult);
010: }
011: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.8 CosDemo/CosDemo.java
Return to top
001: class CosDemo {
002: public static void main(String args[]) {
003: double fp, result;
004: for (fp = -1.0; fp <= 1.0; fp += 0.1) {
005: result = Math.cos(fp);
006: System.out.println("fp = " + fp + ", cosine = " + result);
007: }
008: }
009: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.9 RandomDemo/RandomDemo.java
Return to top
001: class RandomDemo {
002: public static void main(String args[]) {
003: double doubleResult;
004: int intResult;
005: for (int i = 1; i < 10; i++) {
006: doubleResult = Math.random();
007: System.out.print(doubleResult + " /t");
008: intResult = (int)(doubleResult * 100);
009: System.out.println(intResult);
010: }
011: }
012: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.10 Random.txt
Return to top
001: // Random class constructors
002: public Random();
003: public Random(long seed);
004:
005: // Random class methods
006: synchronized public void setSeed(long seed);
007: public void nextBytes(byte[] bytes);
008: public int nextInt();
009: public int nextInt(int n);
010: public long nextLong();
011: public float nextFloat();
012: public double nextDouble();
013: synchronized public double nextGaussian();
Return to top
--------------------------------------------------------------------------------
数值类型 List.11 RandGen/RandGen.java
Return to top
001: import java.util.Random;
002:
003: class RandGen {
004: public static void main(String args[]) {
005: Random generator = new Random();
006: int rows, cols;
007: StringBuffer buffer;
008: for (rows = 1; rows <= 8; rows++) {
009: buffer = new StringBuffer(128);
010: for (cols = 1; cols <= 3; cols++) {
011: buffer.append(generator.nextDouble() + " /t");
012: // buffer.append(generator.nextInt() + " /t");
013: }
014: System.out.println(buffer);
015: }
016: }
017: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.12 RandomBytes/RandomBytes.java
Return to top
001: import java.util.Random;
002:
003: class RandomBytes {
004: static int SIZE = 64; // Number of bytes to generate
005: static byte byteArray[]; // The array of bytes
006:
007: // Display byte array
008: public static void showArray(String label) {
009: System.out.println("/n/n" + label);
010: for (int i = 0; i < byteArray.length; i++) {
011: if (i % 8 == 0)
012: System.out.println(); // Start new row
013: else
014: System.out.print('/t'); // Start new column
015: System.out.print(byteArray[i]);
016: }
017: }
018:
019: public static void main(String args[]) {
020: Random generator = new Random();
021: byteArray = new byte[SIZE];
022: showArray("Before randomizing");
023: generator.nextBytes(byteArray); // Fill array
024: showArray("After randomizing");
025: }
026: }
Return to top
--------------------------------------------------------------------------------
数值类型 List.13 RandomSeed/RandomSeed.java
Return to top
001: import java.util.Random;
002:
003: class RandomSeed {
004: static long SEED = 12345;
005: public static void main(String args[]) {
006: Random generator = new Random(SEED);
007: System.out.println("/nInitial sequence:");
008: for (int i = 0; i < 32; i++)
009: System.out.print(generator.nextInt(100) + " /t");
010: generator.setSeed(SEED); // Reseed the generator
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -