实验内容及步骤:
- 编写”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://www.bianchenghao6.com/h6javajc/19812.html