import java.math.BigInteger; import java.util.Scanner; public class CalculateN { /** * @param args */ public static void main(String[] args) { System.out.print("������N��"); Scanner scanner=new Scanner(System.in); int number=scanner.nextInt(); System.out.println(number+"!="+calculateN2(number)); } public static long calculateN(int n) { if(n==1 || n==0){ return 1; } return n*calculateN(n-1); } public static BigInteger calculateN2(int n) { if(n==1 || n==0){ return BigInteger.valueOf(1); } return BigInteger.valueOf(n).multiply(calculateN2((n-1))); } }
public class CompareFloatNumber { /** * @param args */ public static void main(String[] args) { //compare(); compare2(); } private static void compare() { double i = 0.0001; double j = 0.00010000000000000001; System.out.println(i==j); //�����true } private static void compare2() { double i = 0.0001; double j = 0.00010000000000000001; if(Math.abs(i-j)<1e-10){ System.out.println("true"); } else { System.out.println("false"); } } }
// MethodOverload.java // Using overloaded methods public class MethodOverload { public static void main(String[] args) { System.out.println("The square of integer 7 is " + square(7)); System.out.println("\nThe square of double 7.5 is " + square(7.5)); } public static int square(int x) { return x * x; } public static double square(double y) { return y * y; } }
// RandomInt.java // Shifted, scaled random integers import javax.swing.JOptionPane; public class RandomInt { public static void main( String args[] ) { int value; String output = ""; for ( int i = 1; i <= 20; i++ ) { value = 1 + (int) ( Math.random() * 6 ); output += value + " "; if ( i % 5 == 0 ) output += "\n"; } JOptionPane.showMessageDialog( null, output, "20 Random Numbers from 1 to 6", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } }
// RollDie.java // Roll a six-sided die 6000 times import javax.swing.*; public class RollDie { public static void main( String args[] ) { int frequency1 = 0, frequency2 = 0, frequency3 = 0, frequency4 = 0, frequency5 = 0, frequency6 = 0, face; // summarize results for ( int roll = 1; roll <= 6000; roll++ ) { face = 1 + (int) ( Math.random() * 6 ); switch ( face ) { case 1: ++frequency1; break; case 2: ++frequency2; break; case 3: ++frequency3; break; case 4: ++frequency4; break; case 5: ++frequency5; break; case 6: ++frequency6; break; } } JTextArea outputArea = new JTextArea( 7, 10 ); outputArea.setText( "Face\tFrequency" + "\n1\t" + frequency1 + "\n2\t" + frequency2 + "\n3\t" + frequency3 + "\n4\t" + frequency4 + "\n5\t" + frequency5 + "\n6\t" + frequency6 ); JOptionPane.showMessageDialog( null, outputArea, "Rolling a Die 6000 Times", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } }
public class SquareInt { public static void main(String[] args) { int result; for (int x = 1; x <= 10; x++) { result = square(x); // Math����Ҳ�ṩ����ƽ�����ķ��� // result=(int)Math.pow(x,2); System.out.println("The square of " + x + " is " + result + "\n"); } } // �Զ�����ƽ�����ľ�̬���� public static int square(int y) { return y * y; } }
public class TestMath { public static void main(String[] args) { /*---------��������������---------*/ //������ת���Ƕ� System.out.println("Math.toDegrees(1.57)��" + Math.toDegrees(1.57)); //���Ƕ�ת��Ϊ���� System.out.println("Math.toRadians(90)��" + Math.toRadians(90)); //���㷴���ң����صĽǶȷ�Χ�� 0.0 �� pi ֮�䡣 System.out.println("Math.acos(0.3)��" + Math.acos(1.2)); //���㷴���ң����صĽǶȷ�Χ�� -pi/2 �� pi/2 ֮�䡣 System.out.println("Math.asin(0.8)��" + Math.asin(0.8)); //���㷴���У����صĽǶȷ�Χ�� -pi/2 �� pi/2 ֮�䡣 System.out.println("Math.atan(2.3)��" + Math.atan(2.3)); //�����������ҡ� System.out.println("Math.cos(1.57)��" + Math.cos(1.57)); //����ֵ��˫�����ҡ� System.out.println("Math.cosh(1.2 )��" + Math.cosh(1.2 )); //�������� System.out.println("Math.sin(1.57 )��" + Math.sin(1.57 )); //����˫������ System.out.println("Math.sinh(1.2 )��" + Math.sinh(1.2 )); //������������ System.out.println("Math.tan(0.8 )��" + Math.tan(0.8 )); //����˫������ System.out.println("Math.tanh(2.1 )��" + Math.tanh(2.1 )); //���������� (x, y) ת���ɼ����� (r, thet));���������ý� theta�� System.out.println("Math.atan2(0.1, 0.2)��" + Math.atan2(0.1, 0.2)); /*---------������ȡ������---------*/ //ȡ��������С��Ŀ��������������� System.out.println("Math.floor(-1.2 )��" + Math.floor(-1.2 )); //ȡ�������ش���Ŀ��������С������ System.out.println("Math.ceil(1.2)��" + Math.ceil(1.2)); //��������ȡ�� System.out.println("Math.round(2.3 )��" + Math.round(2.3 )); /*---------�����dz˷���������ָ������---------*/ //����ƽ������ System.out.println("Math.sqrt(2.3 )��" + Math.sqrt(2.3 )); //������������ System.out.println("Math.cbrt(9)��" + Math.cbrt(9)); //����ŷ���� e ��n���ݡ� System.out.println("Math.exp(2)��" + Math.exp(2)); //���� sqrt(x2��" +y2)��û���м���������硣 System.out.println("Math.hypot(4 , 4)��" + Math.hypot(4 , 4)); // ���� IEEE 754 ���Ĺ涨�����������������������㡣 System.out.println("Math.IEEEremainder(5 , 2)��" + Math.IEEEremainder(5 , 2)); //����˷� System.out.println("Math.pow(3, 2)��" + Math.pow(3, 2)); //������Ȼ���� System.out.println("Math.log(12)��" + Math.log(12)); //�������Ϊ 10 �Ķ����� System.out.println("Math.log10(9)��" + Math.log10(9)); // �ز����� 1 ֮�͵���Ȼ������ System.out.println("Math.log1p(9)��" + Math.log1p(9)); /*---------�����Ƿ�����ص�����---------*/ //�������ֵ�� System.out.println("Math.abs(-4.5)��" + Math.abs(-4.5)); //���Ÿ�ֵ�����ش��еڶ������������ŵĵ�һ����������� System.out.println("Math.copySign(1.2, -1.0)��" + Math.copySign(1.2, -1.0)); //���ź������������Ϊ 0��� 标签:9.22,System,static,println,public,Math,out From: https://www.cnblogs.com/baizhuoran/p/17722999.html