CalculateN.java
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 5 public class CalculateN { 6 7 /** 8 * @param args 9 */ 10 public static void main(String[] args) { 11 System.out.print("������N��"); 12 Scanner scanner=new Scanner(System.in); 13 int number=scanner.nextInt(); 14 System.out.println(number+"!="+calculateN2(number)); 15 16 } 17 18 public static long calculateN(int n) { 19 if(n==1 || n==0){ 20 return 1; 21 } 22 23 return n*calculateN(n-1); 24 } 25 26 public static BigInteger calculateN2(int n) { 27 if(n==1 || n==0){ 28 return BigInteger.valueOf(1); 29 } 30 return BigInteger.valueOf(n).multiply(calculateN2((n-1))); 31 } 32 }
运行结果
CompareFloatNumber.java
1 public class CompareFloatNumber { 2 3 /** 4 * @param args 5 */ 6 public static void main(String[] args) { 7 //compare(); 8 compare2(); 9 10 } 11 12 private static void compare() { 13 double i = 0.0001; 14 double j = 0.00010000000000000001; 15 System.out.println(i==j); //�����true 16 } 17 private static void compare2() { 18 double i = 0.0001; 19 double j = 0.00010000000000000001; 20 if(Math.abs(i-j)<1e-10){ 21 System.out.println("true"); 22 } 23 else 24 { 25 System.out.println("false"); 26 } 27 28 } 29 30 }
运行结果
MethodOverload.java
1 package ceshi;// MethodOverload.java 2 // Using overloaded methods 3 4 public class MethodOverload { 5 6 public static void main(String[] args) { 7 System.out.println("The square of integer 7 is " + square(7)); 8 System.out.println("\nThe square of double 7.5 is " + square(7.5)); 9 } 10 11 public static int square(int x) { 12 return x * x; 13 } 14 15 public static double square(double y) { 16 return y * y; 17 } 18 }
运行结果
RandomInt.java
1 package ceshi;// RandomInt.java 2 // Shifted, scaled random integers 3 import javax.swing.JOptionPane; 4 5 public class RandomInt { 6 public static void main( String args[] ) 7 { 8 int value; 9 String output = ""; 10 11 for ( int i = 1; i <= 20; i++ ) { 12 value = 1 + (int) ( Math.random() * 6 ); 13 output += value + " "; 14 15 if ( i % 5 == 0 ) 16 output += "\n"; 17 } 18 19 JOptionPane.showMessageDialog( null, output, 20 "20 Random Numbers from 1 to 6", 21 JOptionPane.INFORMATION_MESSAGE ); 22 23 System.exit( 0 ); 24 } 25 }
运行结果
RollDie.java
1 package ceshi;// RollDie.java 2 // Roll a six-sided die 6000 times 3 import javax.swing.*; 4 5 public class RollDie { 6 public static void main( String args[] ) 7 { 8 int frequency1 = 0, frequency2 = 0, 9 frequency3 = 0, frequency4 = 0, 10 frequency5 = 0, frequency6 = 0, face; 11 12 // summarize results 13 for ( int roll = 1; roll <= 6000; roll++ ) { 14 face = 1 + (int) ( Math.random() * 6 ); 15 16 switch ( face ) { 17 case 1: 18 ++frequency1; 19 break; 20 case 2: 21 ++frequency2; 22 break; 23 case 3: 24 ++frequency3; 25 break; 26 case 4: 27 ++frequency4; 28 break; 29 case 5: 30 ++frequency5; 31 break; 32 case 6: 33 ++frequency6; 34 break; 35 } 36 } 37 38 JTextArea outputArea = new JTextArea( 7, 10 ); 39 40 outputArea.setText( 41 "Face\tFrequency" + 42 "\n1\t" + frequency1 + 43 "\n2\t" + frequency2 + 44 "\n3\t" + frequency3 + 45 "\n4\t" + frequency4 + 46 "\n5\t" + frequency5 + 47 "\n6\t" + frequency6 ); 48 49 JOptionPane.showMessageDialog( null, outputArea, 50 "Rolling a Die 6000 Times", 51 JOptionPane.INFORMATION_MESSAGE ); 52 System.exit( 0 ); 53 } 54 }
运行结果
SquareInt.java
1 package ceshi; 2 3 public class SquareInt { 4 5 public static void main(String[] args) { 6 int result; 7 8 for (int x = 1; x <= 10; x++) { 9 result = square(x); 10 // Math����Ҳ�ṩ����ƽ�����ķ��� 11 // result=(int)Math.pow(x,2); 12 System.out.println("The square of " + x + " is " + result + "\n"); 13 } 14 } 15 16 // �Զ�����ƽ�����ľ�̬���� 17 public static int square(int y) { 18 return y * y; 19 } 20 }
运行结果
TestMath.java
1 package ceshi; 2 3 4 public class TestMath 5 { 6 public static void main(String[] args) 7 { 8 /*---------��������������---------*/ 9 //������ת���Ƕ� 10 System.out.println("Math.toDegrees(1.57)��" + Math.toDegrees(1.57)); 11 //���Ƕ�ת��Ϊ���� 12 System.out.println("Math.toRadians(90)��" + Math.toRadians(90)); 13 //���㷴���ң����صĽǶȷ�Χ�� 0.0 �� pi ֮�䡣 14 System.out.println("Math.acos(0.3)��" + Math.acos(1.2)); 15 //���㷴���ң����صĽǶȷ�Χ�� -pi/2 �� pi/2 ֮�䡣 16 System.out.println("Math.asin(0.8)��" + Math.asin(0.8)); 17 //���㷴���У����صĽǶȷ�Χ�� -pi/2 �� pi/2 ֮�䡣 18 System.out.println("Math.atan(2.3)��" + Math.atan(2.3)); 19 //�����������ҡ� 20 System.out.println("Math.cos(1.57)��" + Math.cos(1.57)); 21 //����ֵ��˫�����ҡ� 22 System.out.println("Math.cosh(1.2 )��" + Math.cosh(1.2 )); 23 //�������� 24 System.out.println("Math.sin(1.57 )��" + Math.sin(1.57 )); 25 //����˫������ 26 System.out.println("Math.sinh(1.2 )��" + Math.sinh(1.2 )); 27 //������������ 28 System.out.println("Math.tan(0.8 )��" + Math.tan(0.8 )); 29 //����˫������ 30 System.out.println("Math.tanh(2.1 )��" + Math.tanh(2.1 )); 31 //���������� (x, y) ת���ɼ����� (r, thet));���������ý� theta�� 32 System.out.println("Math.atan2(0.1, 0.2)��" + Math.atan2(0.1, 0.2)); 33 /*---------������ȡ������---------*/ 34 //ȡ��������С��Ŀ��������������� 35 System.out.println("Math.floor(-1.2 )��" + Math.floor(-1.2 )); 36 //ȡ�������ش���Ŀ��������С������ 37 System.out.println("Math.ceil(1.2)��" + Math.ceil(1.2)); 38 //��������ȡ�� 39 System.out.println("Math.round(2.3 )��" + Math.round(2.3 )); 40 /*---------�����dz˷���������ָ������---------*/ 41 //����ƽ������ 42 System.out.println("Math.sqrt(2.3 )��" + Math.sqrt(2.3 )); 43 //������������ 44 System.out.println("Math.cbrt(9)��" + Math.cbrt(9)); 45 //����ŷ���� e ��n���ݡ� 46 System.out.println("Math.exp(2)��" + Math.exp(2)); 47 //���� sqrt(x2��" +y2)��û���м���������硣 48 System.out.println("Math.hypot(4 , 4)��" + Math.hypot(4 , 4)); 49 // ���� IEEE 754 ���Ĺ涨�����������������������㡣 50 System.out.println("Math.IEEEremainder(5 , 2)��" + Math.IEEEremainder(5 , 2)); 51 //����˷� 52 System.out.println("Math.pow(3, 2)��" + Math.pow(3, 2)); 53 //������Ȼ���� 54 System.out.println("Math.log(12)��" + Math.log(12)); 55 //�������Ϊ 10 �Ķ����� 56 System.out.println("Math.log10(9)��" + Math.log10(9)); 57 // �ز����� 1 ֮�͵���Ȼ������ 58 System.out.println("Math.log1p(9)��" + Math.log1p(9)); 59 /*---------�����Ƿ�����ص�����---------*/ 60 //�������ֵ�� 61 System.out.println("Math.abs(-4.5)��" + Math.abs(-4.5)); 62 //���Ÿ�ֵ�����ش��еڶ������������ŵĵ�һ����������� 63 System.out.println("Math.copySign(1.2, -1.0)��" + Math.copySign(1.2, -1.0)); 64 //���ź������������Ϊ 0��� 标签:9.22,java,代码,System,测试,println,public,Math,out From: https://www.cnblogs.com/lijianlongCode13/p/17723037.html