首页 > 其他分享 >9.22(代码测试)

9.22(代码测试)

时间:2023-09-22 17:58:13浏览次数:38  
标签:9.22 java 代码 System 测试 println public Math out

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

相关文章

  • 关于表单快速开发低代码技术平台的内容介绍
    运用什么样的表单快速开发软件平台可以实现高效率创收?随着科技的进步和飞速发展,专业的低代码技术平台已经走入了很多企业的办公职场中,它们灵活、轻量级、优质、高效、易维护等优势特点,可以高效助力广大企业提质增效,并且利用数据资源,实现流程化办公。什么是低代码技术平台?其实,低代......
  • 9.22
    importjava.math.BigInteger;importjava.util.Scanner;publicclassCalculateN{/***@paramargs*/publicstaticvoidmain(String[]args){System.out.print("������N��");Scannerscanner=newScanner(System......
  • gtest测试框架
    GoogleTest简单使用googleTest是谷歌公司发布的一个跨平台的C++单元测试框架两种断言致命断言ASSERT_*:当断言失败时,产生致命错误,并终止当前函数非致命断言EXPECT_*:当断言失败时,产生非致命错误,并不会终止当前函数常用的断言ASSERTEXPECTVerifiesASSERT_TRUE(cond......
  • 自动化测试-友好的第三方库
    自动化测试脚本开发中,总是会遇到各种数据处理,例如MOCK、URL处理、JSON数据处理、结果断言等,也会遇到所采用的测试框架不能满足当前需求,这些问题都需要我们自己动手解决。在强大的IT世界,我们遇到的百分之九十八问题,前辈们都遇到过并且给出了解决方案,有的无私前辈将其整理并开源,这些......
  • 9.22
    编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数importjava.util.ArrayList;importjava.util.List;publicclassRandomNumberGenerator{privatestaticfinallongMULTIPLIER=1664525;//线性同余发生器的乘数privatestaticfinallongINCR......
  • 软件开发中,如何为你的代码构建三层防护体系
    本文分享自华为云社区《构建DevSecOps中的代码三层防护体系》,作者:Uncle_Tom。在DevSecOps的应用过程中,静态分析工具在开发阶段承担着非常重要的代码质量和安全的看护任务。本文根据开发过程的不同位置的开发环境、代码特征以及检测工具能力的差异,提出了需要因地制宜地部署检查工......
  • 如何提升Java项目质量,代码是关键
    关于编程,代码质量是一个极其重要的因素。无论是初学者还是资深开发者,都深知高质量代码的重要性,除了可以提高程序的可维护性,还能减少错误和问题的出现。尤其在像Java这样受欢迎但难度较高的编程语言中,代码质量显得尤为突出。要想写出高质量的Java代码,并不是一件容易的事情。你可能......
  • 9.22
    之前忘了完成动手动脑的作业,正好今天没课先写动手动脑再去想怎么完成javaweb的界面一、Math类的测试反函数在前面加a,双曲在后面加h熟练掌握数学类函数能够让之后代码中的计算变得更加方便publicclasswork{publicstaticvoidmain(String[]args){/*--......
  • 9.22动手动脑
    一、动手动脑1importjava.util.Random;publicclassRandomNumberGenerator{publicstaticvoidmain(String[]args){generateRandomNumbers(1000);}publicstaticvoidgenerateRandomNumbers(intcount){intmodulus=231-1;......
  • 2023.9.22 AT practise
    ARC083F显然每个小球必须被\((0,y)\)或\((x,0)\)中的一个收掉,那么把\(i\)的球看成一条边,链接两个机器人。因为\(2n\)个小球对应\(2n\)条边,故建图出来是一个基环树森林。考虑把每条边定向,对应的就是那个球被那个机器人收了。那么每个基环树只有两种情况(环的方向)。现......