JAVA复习资料

上传人:文*** 文档编号:371241 上传时间:2018-07-05 格式:DOCX 页数:24 大小:979.96KB
返回 下载 相关 举报
JAVA复习资料_第1页
第1页 / 共24页
JAVA复习资料_第2页
第2页 / 共24页
JAVA复习资料_第3页
第3页 / 共24页
点击查看更多>>
资源描述
编写程序,从控制台读入 double 型的摄氏温度,然后将其转换为华氏温度,并且显示结果。转换公式如下:华氏温度 = (9/5)* 摄氏温度 + 32import java.util.*;class Test21public static void main(String args) System.out.printf(请输入需要转换的摄氏温度:);Scanner S=new Scanner(System.in);double a=S.nextDouble();System.out.println(该摄氏温度转换为华氏温度为+(9.0/5)*a+32);编写程序,读入圆柱体的半径和高,并使用下列公式计算圆柱的体积:面积 = 半径 半径 P体积 = 面积 高import java.util.*;class Test22 public static void main(String args) System.out.printf(请分别输入圆柱的半径和高:);double pi=Math.PI;double S;Scanner Y=new Scanner(System.in);double m=Y.nextDouble();double n=Y.nextDouble();S=a*a*pi;System.out.println(面积为:+S);System.out.println(体积为:+(S*n);编写程序,读取一个在 0 和 1000 之间的整数,并将该整数的各位数字相加。例如:整数是 932,各位数字之和为 14。import java.util.*;class Test26public static void main(String args) System.out.printf(请输入一个在 0 到 1000 之间的整数:);Scanner N=new Scanner(System.in);int a=N.nextInt();int x=0,y=0;while(a!=0)x=a%10;a=a/10;y=y+x;System.out.printf(该数的各位数字之和为:+y);编写一个随机产生 1 和 12 之间整数的程序,并且根据数字 1,2,12 显示相应的英文月份:January,February,December。import java.util.*;class Test34public static void main(String args) int a=1+(int)(Math.random()*12);switch(a)case 1:System.out.println(January);break;case 2:System.out.println(February);break;case 3:System.out.println(March);break;case 4:System.out.println(Apirl);break;case 5:System.out.println(May);break;case 6:System.out.println(June);break;case 7:System.out.println(July);break;case 8:System.out.println(August);break;case 9:System.out.println(September);break;case 10:System.out.println(October);break; case 11:System.out.println(November);break;default:System.out.println(December);编写程序,提示用户输入三个整数。以非降序的形式显示这三个整数。import java.util.*;class Test38 public static void main(String args) System.out.print(输入三个整数 a,b,c:);Scanner scanner=new Scanner(System.in);int a=scanner.nextInt();int b=scanner.nextInt();int c=scanner.nextInt();int m,n,o;if(ab)o=a;a=b;b=o;if(ac)m=a;a=c;c=m;if(bc)n=b;b=c;c=n;System.out.println(a+n+b+n+c+n);编写程序,提示用户输入一个点(x,y) ,然后检查这个点是否在以原点(0,0)为圆心,半径为 10 的圆内。例如:(4,5)是圆内的一点,而(9,9)是圆外的一点。import java.util.*;class Test322public static void main(String args) System.out.print(请输入一个含有两个点的坐标:);Scanner scanner=new Scanner(System.in);double number1=scanner.nextDouble();double number2=scanner.nextDouble();double distance=Math.sqrt(Math.pow(number1,2)+(Math.pow(number2,2);if(distance=0;m-)System.out.print(int)Math.pow(2, m);System.out.print( );System.out.println();打印 2 到 1000 之间,包括 2 和 1000 的所有素数,每行显示 8 个素数。数字之间用一个空格字符隔开。import java.util.*;public class Test520 public static boolean isPrime(int num) boolean prime = true;int limit = (int) Math.sqrt(num);for (int i = 2; i =0)c+;gc=scanner.nextDouble();for(int i=0;i=ave)m+; elsen+; System.out.println(m+个分数大于等于平均分+ave);System.out.println(n+个分数小于平均分+ave);使用冒泡排序算法编写一个排序方法。import java.util.*;class Test718public static void main(String args)double a;a=new double10;Scanner scanner=new Scanner(System.in);System.out.print(请输入 10 个数: );for(int i=0;i=aj+1)double t=aj;aj=aj+1;aj+1=t;System.out.print(排序后的数组为: );for(int i=0;i20) t = 0;if(Thread.currentThread() = RedBall)int x = 50;int y = (int)(1.0/2*t*t*9.8)+50;red.setLocation(x, y);tryThread.sleep(45);catch (InterruptedException e)e.printStackTrace();else if(Thread.currentThread() = BlueBall)int x = 50 + (int)(40*t);int y = (int)(1.0/2*t*t*9.8)+50;blue.setLocation(x, y);tryThread.sleep(45);catch (InterruptedException e)e.printStackTrace();实现一个窗口,在 North 区域添加一个面板,布局用 FlowLayout,在面板上添加两个按钮,在窗口 Center 区域添加一个面板,布局用 GridLayout.import javax.swing.*;import java.awt.*;import java.awt.event.*;class Demo extends JFrameDemo()super(我的窗口);JPanel contentPanel = (JPanel)getContentPane();JPanel np = new JPanel();np.add(new JButton(1);np.add(new JButton(2);contentPanel.add(np,BorderLayout.NORTH);JPanel cp = new JPanel();cp.setLayout(new GridLayout(3,3);for(int i=0;i results = new HashMap();/* F0 =0; * F1=1 (n=1) * F2=1 (n=2) * Fn=Fn-1+Fn-2 (n=3) */public static int fib(int i) int result;if (i = 0) result = 0; else if (i = 1) result = 1; else result = fib(i - 1) + fib(i - 2);results.put(i, result);return result;public static void main(String args) int cnt = 20;Fib.fib(cnt);for (int i = 0; i =aj+1)double t=aj;aj=aj+1;aj+1=t;System.out.print(排序后的数组为: );for(int i=0;i10;i+)System.out.print(ai+ );
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!