代碼如下,隨便附壹句,壹定要看寫的源碼,我已經盡量馬馬虎虎的寫了,妳更容易看懂。
public?class?Test?{//?第八題
public?static?final?int?NUM?=?100;
public?static?final?double?GOOD?=?99.99;
public?static?final?String?CLASSNAME?=?"Test.Class";
public?static?final?long?MAX?=?9999999;
public?static?void?main(String[]?args)?{
//?第壹題
byte?byte1?=?1;
short?short1?=?1;
int?int1?=?1;
long?long1?=?1;
float?float1?=?1;
double?double1?=?1.0;
System.out.println("byte1?-?"?+?byte1);
System.out.println("short1?-?"?+?short1);
System.out.println("int1?-?"?+?int1);
System.out.println("long1?-?"?+?long1);
System.out.println("float1?-?"?+?float1);
System.out.println("double1?-?"?+?double1);
//?第二題
String?name;
char?sex;
int?age;
boolean?isMember;
//?第三題
int?score1;
double?score2?=?98.5;
//?第四題
double?f1?=?10.1,?f2?=?34.2;
System.out.println("f1,f2的和:"?+?(f1?+?f2));
System.out.println("f1,f2的差:"?+?(f1?-?f2));
System.out.println("f1,f2的積:"?+?(f1?*?f2));
System.out.println("f1,f2的商:"?+?(f1?/?f2));
//?第五題
int?f3?=?5;
double?f4?=?45.6;
System.out.println("f3,f4的和:"?+?(f3?+?f4));
System.out.println("f3,f4的差:"?+?(f3?-?f4));
System.out.println("f3,f4的積:"?+?(f3?*?f4));
System.out.println("f3,f4的商:"?+?(f3?/?f4));
//?第六題
int?A?=?65;
char?a?=?(char)?A;
System.out.println("整型互轉char:"?+?a);
//?第七題
double?timor?=?123.456789;
int?x?=?Integer
.parseInt(new?java.text.DecimalFormat("0").format(timor));//?四舍五入
System.out.println("double?->?int?:"?+?x);
//?第八題(定義在最開始)
System.out.println("常量NUM的值:?"?+?NUM);
System.out.println("常量GOOD的值:?"?+?GOOD);
System.out.println("常量CLASSNAME的值:?"?+?CLASSNAME);
System.out.println("常量MAX的值:?"?+?MAX);
//?第九題(自定義商品類)
class?Goods?{
private?String?name;
private?double?price;
private?int?count;
private?double?total;
public?Goods(String?name,?double?price,?int?count)?{
this.name?=?name;
this.price?=?price;
this.count?=?count;
}
public?void?print()?{
total?=?price?*?count;
System.out.println("商品名 ?價格?數量 ?總價");
System.out.println(name?+?" ?"?+?price?+?" ?"?+?count?+?" ?"
+?total);
}
}
Goods?goods?=?new?Goods("蘋果",?2,?10);
goods.print();
//?第十題
double?pi?=?3.14,?r,?d;
r?=?4;
d?=?2?*?r;
System.out.println("圓的周長:?"?+?(pi?*?d));
System.out.println("圓的面積:?"?+?(pi?*?r?*?r));
//?第十壹題
String?qqname?=?"1234567890";
String?qqpassword?=?"asd!#@#$%66";
Date?birth?=?new?Date(2014,?5,?1);
boolean?isVIP?=?false;
char?sex1?=?'男';
StringBuilder?personInfo?=?new?StringBuilder();
personInfo.append("我是壹個快樂的騷年");
personInfo
.append("然後a!#$%^&*asdasdasdasdsa9d87a9s8d79asdjidauisdhausdihiasd");
//?第十二題
class?Swaper?{
public?void?change(int?num1,?int?num2)?{
int?temp?=?num1;
num1?=?num2;
num2?=?temp;
System.out.printf("a=%d,b=%d\n",?num1,?num2);
}
}
int?a1?=?2;
int?b1?=?5;
Swaper?swaper?=?new?Swaper();
swaper.change(a1,?b1);
}
}