50,503
社区成员
发帖
与我相关
我的任务
分享
public class Hello{
public static void main(String[] args){
System.out.println("您好世界");
}
}
public class juxing{
public static void main(String args[]){//Java程序从主类的main方法开始运行
Rect juxing1,juxing2;//用类(Rect)声明对象
juxing1=new Rect();//为对象分配变量,new是运算符
juxing2=new Rect();//同上
juxing1.width=128;//对象用‘.’操作变量。对象存在了Rect类里,上面用运算符new已经分配。
juxing1.height=69;
juxing2.width=18.9;
juxing2.height=59.8;
double area1=juxing1.getarea();//对象用‘.’调用方法。方法同样存在Rect类里
double area2=juxing2.getarea();
System.out.println("矩形1的面积是"+area1);
System.out.println("矩形2的面积是"+area2);
}
} /*问题1:String[] args和String args[]的区别在哪里?
//答:执行效果上没有不同, 但在语法意义上略有不同. 比如, String与String[], 前者叫字符串类型而后者叫字符串数组类型.
//例:String args[], argt; String[] args, argt; 这就有很显示的差异了. 在第一句中args是字符串数组类型, 而argt就////是字符串变量. 在第二句中args与argt都是字符串数组类型.那就是:string[] args,声明一个String数组,名字叫args. string args[],声明//一个叫args的数组,类型是String. 跟Rect文件在同一目录下
*/
public class Rect{
double width;
double height;
double getarea(){
double area=width*height;
return area;
}
}