第二次动手动脑(听说胡图图是爱动小筋的脑孩)
动手动脑
一
1.题目
2.代码
/*---------��������������---------*/
//������ת���Ƕ�
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));
System.out.println("Math.signum(2.3)��" + Math.signum(2.3));
System.out.println("Math.max(2.3 , 4.5)��" + Math.max(2.3 , 4.5));
System.out.println("Math.min(1.2 , 3.4)��" + Math.min(1.2 , 3.4));
System.out.println("Math.nextAfter(1.2, 1.0)��" + Math.nextAfter(1.2, 1.0));
System.out.println("Math.nextUp(1.2 )��" + Math.nextUp(1.2 ));
System.out.println("Math.random()��" + Math.random());
3.运行结果
二
1.问题
2.代码
import javax.swing.*;
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 );
3.运行结果
三
1.问题
2.代码
// TODO Auto-generated method stub
long seed = System.currentTimeMillis();// 种子
int i;
int count = 0;
// Modulus=231-1=int.MaxValue
// Multiplier=75=16807
long random = (16807 * seed) % Integer.MAX_VALUE;
for (i = 1; i <= 1000; i++) {
random = (16807 * random) % Integer.MAX_VALUE;
System.out.print(random + " ");
count++;
if (count % 5 == 0)
System.out.println();
}
3.运行结果