JAVA复习资料_第1页
JAVA复习资料_第2页
JAVA复习资料_第3页
JAVA复习资料_第4页
JAVA复习资料_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

编写程序,从控制台读入 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;i10;i+)System.out.print(ai+“ “);编写一个方法,求整数矩阵中特定列的所有元素的和,使用下面的方法头:public static double sumColumn(double m,int columnIndex)import java.util.*;class Test81public static void main(String args) int m,n;double s;double a;Scanner input=new Scanner(System.in);System.out.println(“Enter the row and the column of the array: “);m=input.nextInt();n=input.nextInt();System.out.println(“Enter a “+m+“-by-“+n+“ matrix row by row:“);a=new doublemn;for(int row=0;rowa.length;row+) for(int column=0;columnarow.length;column+) arowcolumn=input.nextDouble();for(int i=0;in;i+)s=sumColumn(a,i);System.out.println(“Sum of the elements at column “+i+“ is “+s);public static double sumColumn(double m,int columnIndex) double sum=0;for(int i=0;im.length;i+)sum=sum+micolumnIndex

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论