实验内容及步骤:
- 编写”hello world”应用程序。
(1)代码:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
(2)运行结果:

- 编写有数组的程序。
(1)代码:
public class TestTravel
{
public static void main(String[] args)
{
int[]arr01=new int[10];
for (int i=0;i<arr01.length-1;i++)
{
arr01[i]=i+1;
}
for (int i=0;i<=arr01.length-1;i++)
{
if(arr01[i]%3==0)
{
实验内容及步骤:
System.out.println("arr01[" + i + "]=" + arr01[i]);
}
}
}
}
(2)运行结果:
java基础实验报告一
- 编写有选择结构和循环结构的程序。
(1)代码:
public class TestNum
{
public static void main(String[] args)
{
//水仙花数

for(int n = 100;n < 1000;n ++)
{
int i = n / 100;
int j = n / 10 % 10;
int k = n % 10;
if(Math.pow(i,3) + Math.pow(j,3) + Math.pow(k,3) == n)
{
System.out.println(n + "是水仙花数");
}
}
}
}
(2)运行结果:

实验内容及步骤:
- 编写有方法的程序。
(1)代码:
public class Area {
public static void main(String[] args)
{
double r=3;
double a=5;
double b=12;
System.out.println("圆的面积:"+area(r));
System.out.println("长方形的面积:"+area(a,b));
}
static double area(double r)
{
return Math.PI*r*r;
}
static double area(double a,double b)
{
return a*b;
}
}
(2)运行结果:

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/9984.html