实验一
,在屏幕上显示如下信息:
**************************
e<你的名字>
**************************
想一想:怎样让用户在运行程序的时候指定“你的名字”
public class Experiment1_1 {
public static void main(String[] args) {
( "*************************");
( " e 宁");
( "*************************");
}
}
2. 写一个Java程序打印出下列信息:
姓名
性别
年龄
学号
系和专业
兴趣爱好
public class Experiment1_2 {
public static void main(String args[])
{
("姓名");
("性别");
("年龄");
("学号");
("系和专业");
("兴趣爱好");
}
}
,使用while循环计算1~1000之间能被3和7同时整除的整数之和
public class Experiment1_3 {
public static void main(String[] args) {
int i=1;
int sum=0;
while(i<=1000)
{
if(i%7==0&&i%3==0)
sum+=i;
i++;
}
("sum="+sum);
}
}
实验二
有一函数,编写一个程序,从键盘输入一个x值,程序输出y的值
import ;
public class Experiment2_1 {
public static void main(String[] args) {
Scanner reader=new Scanner();
int x=();
if(x<0)
(-1+2*x);
else if(x==0)
(-1);
else
(-1+3*x);
}
}
编写一个程序,使用for循环计算8+88+888+8888+…的前十项之和
要求:在上述程序中设置断点和观察点进行单步调试
public class Experiment2_2 {
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;
}
("sum="+sum);
}
}
利用for循环打印 9*9 表
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*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=81
要求:对上述程序中的方法和语句加上注释
public class Experiment2_3 {
public static void main(String[] args) {
for(int i=1;i<10;i++)
{
for(int j=1;j<=i;j++)
("%4d*%d=%d",i,j,j
java实验报告 来自淘豆网m.daumloan.com转载请标明出处.