java实验及答案.doc
《java实验及答案.doc》由会员分享,可在线阅读,更多相关《java实验及答案.doc(64页珍藏版)》请在三一办公上搜索。
1、Java实验级答案实验一1. 编写一个程序,在屏幕上显示如下信息: * welcome*2. 写一个Java程序打印出下列信息:姓名 性别 年龄 学号系和专业兴趣爱好3. 编写一个程序,使用while循环计算11000之间能被3和7同时整除的整数之和实验一答案1.1public class welcome public static void main(String args) System.out.println(*); System.out.println( welcome 孙强 ); System.out.println(*);1.2public class Information pu
2、blic static void main(String args)System.out.println(姓名:xxx );System.out.println(性别:女);System.out.println(年龄:18);System.out.println(学号:20132214xxx);System.out.println(系和专业:xxxx);System.out.println(兴趣爱好:Java);1.3public class Sum public static void main(String args) int i=1; int sum=0; while(i=1000) i
3、f(i%7=0&i%3=0) sum+=i; i+; System.out.print(sum=+sum);实验二1. 有一函数,编写一个程序,从键盘输入一个x值,程序输出y的值2. 编写一个程序,使用for循环计算8+88+888+8888+的前十项之和3. 利用for循环打印 9*9 表1*1=11*2=2 2*2=41*3=3 2*3=6 3*3=91*4=4 2*4=8 3*4=12 4*4=161*5=5 2*5=10 3*5=15 4*5=20 5*5=251*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=361*7=7 2*7=14 3*7=21 4*7
4、=28 5*7=35 6*7=42 7*7=491*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=641*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=814. 从键盘输入一个百分制的成绩,输出相应的等级。 90分以上 A级 8089 B级 7079 C级 6069 D级 60分以下 E级实验二答案2.1package cn.ldu.sun;import java.util.Scanner;public class formula public static void ma
5、in(String args) Scanner reader=new Scanner(System.in);int i=reader.nextInt();if(i0)System.out.println(-1+3*i);else System.out.println(-1);2.2package cn.ldu.sun;public class Sum2 public static void main(String args) int sum=0;int temp=8;for(int i=1;i=10;i+)sum+=temp;temp=temp*10+8;System.out.println(
6、sum=+sum);2.3package cn.ldu.sun;public class multiplication public static void main(String args) for(int i=1;i10;i+) for(int j=1;j=i;j+) System.out.print(j+*+i+=+i*j+ ); System.out.print(n); 2.4package cn.ldu.sun;import java.util.Scanner;public class Score public static void main(String args) Scanne
7、r reader=new Scanner(System.in); int score=reader.nextInt();switch(score/10)case 10: case 9:System.out.println(A);break;case 8:System.out.println(B);break;case 7:System.out.println(C);break;case 6:System.out.println(D);break;case 5:case 4:case 3:case 2:case 1:case 0:System.out.println(E);break;defau
8、lt:System.out.println(ERROR);实验三1. 使用Java编写控制台应用程序,用户从键盘输入月份,使用switch语句输出该月份的天数,如果输入月份为2月份,则程序提示让用户输入年份,再输出结果。2. 使用Java编写控制台应用程序,输出九九乘法表。3. 使用Java编写控制台应用程序,计算有固定收入的党员每月所交纳的党费。月工资收入400元及以下者,交纳月工资总额的0.5%;月工资收入401600元者,交纳月工资总额的1%;月工资收入601800元者,交纳月工资总额的1.5%;月工资收入8011500元者,交纳月工资总额的2%;月工资收入1500元以上者,交纳月工资总
9、额的3%。4. 使用Java编写控制台应用程序,用户从键盘输入n天的温度,n由用户指定,求出平均温度、最高和最低温度。实验三答案3.1package exercise1;import java.util.*;public class Month public static void main(String args)Scanner reader=new Scanner(System.in);int month;System.out.printf(请用户输入月份:);int day=0;month=reader.nextInt();if(month=2) System.out.printf(请用
10、户输入年份:); int year=reader.nextInt(); if(year%4=0&year%100!=0|year%400=0) day=29; else day=28;switch(month)case 1:case 3: case 5:case 7:case 8:case 10:case 12: day=31;break;case 4:case 6:case 9:case 11: day=30;break;default: System.out.printf(该月份对应天数为:%d,day);3.2public class Sanjiujiu public static vo
11、id main(String args)for(int i=1;i=9;i+)for(int j=1;j=i;j+)System.out.printf(%d*%d=%-2d,j,i,i*j);System.out.printf( );System.out.printf(n);System.out.printf(n);System.out.printf(n);for(int i=1;i=9;i+)for(int j=1;j=9;j+)System.out.printf(%d*%d=%-2d,i,j,i*j);System.out.printf( );System.out.printf(n);Sy
12、stem.out.printf(n);System.out.printf(n);for(int i=1;i=9;i+)for(int j=i;j=9;j+)System.out.printf(%d*%d=%-2d,i,j,i*j);System.out.printf( );System.out.printf(n);for(int k=1;k=i;k+)System.out.printf( ); 3.3import java.util.*;public class Salary public static void main(String args)Scanner reader=new Scan
13、ner(System.in);System.out.printf(请用户输入工资:);float salary;float _out = 0;salary=reader.nextFloat();if(salary=0)_out=(float)(salary*(0.5/100);else if(salary=401&salary=601&salary=801&salary=1500)_out=(float)(salary*(2/100);else_out=(float)(salary*(3/100);System.out.printf(应缴税:%f,_out);3.4import java.ut
14、il.*;public class Temperature public static void main(String args)System.out.printf(How many days temperatures?);Scanner reader=new Scanner(System.in);int day=0;int sum=0;int max=0;int min=0;float average=0;day=reader.nextInt();for(int i=1;i=5;i+)int tem=reader.nextInt();System.out.printf(Day%ds tem
15、perature is:%d,i,tem);sum+=tem;if(maxtem)min=tem; average=(float)(sum/5.0);System.out.printf(Average temperature:%f,average);System.out.printf(Maxmun temperature:%d,max);System.out.printf(Minmum temperature:%d,min);实验四1. 定义一个int型的一维数组,包含10个元素,从键盘分别赋一些随机整数,然后求出所有元素的最大值,最小值,平均值,和值,并输出出来。2. 定义一个int型的一维
16、数组,包含10个元素,分别赋值为1-10, 然后将数组中的元素都向前移一个位置,即,a0=a1,a1=a2,最后一个元素的值是原来第一个元素的值,然后输出这个数组。3. 定义一个int型的一维数组,包含40个元素,用来存储每个学员的成绩,循环产生40个0-100之间的随机整数,将它们存储到一维数组中,然后统计成绩低于平均分的学员的人数,并输出出来。4. 创建一个整型数组f,拥有20个元素,并将它的各个元素赋值如下,然后,输出它们,并编写一段程序输出fn的值,其中,n为任意 f0=1, f1=2 fi=fi-1+fi-2实验四答案4.1import java.util.*;public clas
17、s shuzu1 public static void main(String args) int a=new int 10;int max=a0;int min=a0;int b,c;double sum=0;double avg=0;for (int i=0;i10;i+) ai=(int)(Math.random()*100);for(b=0;b=9;b+)if(maxai)max=ai;for(c=0;cai)min=ai;for(int a=0;a=a.length;a+)sum+=a;avg=sum/a.length;System.out.println(ai);System.ou
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 实验 答案

链接地址:https://www.31ppt.com/p-2386898.html