public class Application2_1 {public static void main (String args[ ]) {【代码1】//声明名字是temperature的byte型变量,并指定初值是0【代码2】//声明名字是peopleNumber的short型变量,不指定初值int moneyAmount = 100;long number = 2000;temperature = -26;System.out.printf("目前冷冻设备的温度是%d度,能达到的最低温度是%d\n",temperature,Byte.MIN_VALUE);【代码3】//将常量32000赋值给peopleNumberSystem.out.printf("这个体育场昨天来了%d人,体育场最多能容纳%d人\n",peopleNumber,Short.MAX_VALUE);moneyAmount = 21999999;System.out.printf("保险柜存放了%d元,最多能存放%d元\n",moneyAmount,Integer.MAX_VALUE);【代码4】 //将常量999999999999L赋值给numberSystem.out.printf("Java能处理%d,能处理的最大整数是%d\n",number,Long.MAX_VALUE);}}
查看答案
public class Application2_2 {public static void main (String args[ ]) {【代码1】 //用char声明名字为chinaWord和japanWord的变量,初值分别是'好'和'ぁ'【代码2】 //用char声明名字为you的变量,初值是65【代码3】 //用int声明名字为position的变量,初值是20320System.out.printf("汉字:%c的索引位置:%d\n",chinaWord,(int)chinaWord);System.out.printf("日文:%c的索引位置:%d\n",japanWord,(int)japanWord);System.out.printf("%d位置上的字符是:%c\n",position,(char)position);char fire = 119;char warnning = '火';System.out.printf("火警电话是%d,%c%c%c%c",(int)fire,warnning,warnning,warnning,warnning);【代码4】 //输出一对双引号}}
public class Application2_3 {public static void main (String args[ ]) {int unitPrice = 789;【代码1】 //用float声明名字是goldMeasure1的变量【代码2】 //用double声明名字是goldMeasure2的变量;double price;【代码3】 //将float常量8.987654321f赋值给goldMeasure1price = unitPrice*goldMeasure1;System.out.printf("计量工具1显示的戒指的质量是:%12.10f\n",goldMeasure1);System.out.printf("根据计量工具1给出戒指的价格是:%f元\n",price);【代码4】 //将double常量8.987654321赋值给goldMeasure2price = unitPrice*goldMeasure2;System.out.printf("计量工具2显示的戒指的质量是:%12.10f\n",goldMeasure2);System.out.printf("根据计量工具2给出戒指的价格是:%f元\n",price);}}
public class Application2_4 {public static void main (String args[ ]) {short a,b,c;【代码1】 //用boolean声明名字是isTriangle变量a = 5;b = 4;c = 3;if(a+b>c&&a+c>b&&b+c>a)【代码2】 //true赋值给isTriangleelse【代码3】 // false赋值给isTriangleSystem.out.printf("%d,%d,%d构成三角形吗?回答:%b\n",a,b,c,isTriangle);a = 15;b = 40;c = 73;if(a+b>c&&a+c>b&&b+c>a)isTriangle = true;elseisTriangle = false;System.out.printf("%d,%d,%d构成三角形吗?回答:%b\n",a,b,c,isTriangle);}}
import java.util.Scanner;public class Application2_5 {public static void main (String args[ ]) {Scanner reader = new Scanner(System.in);double weight,chargeWeight,charge;System.out.printf("输入行李重量:");weight = reader.nextDouble();【代码1】 //将 (int)weight赋值给chargeWeightSystem.out.printf("行李重量:%f(kg),火车的计费重量:%f(kg)\n",weight,chargeWeight);【代码2】 //将chargeWeight*12.6的值赋值给chargeSystem.out.printf("用火车托运的费用:%f元\n", charge);【代码3】//将 (int)(weight+0.5)赋值给chargeWeightSystem.out.printf("行李重量:%f(kg),汽车计费重量:%f(kg)\n",weight,chargeWeight);【代码4】//将chargeWeight*22.5的值赋值给chargeSystem.out.printf("用汽车托运的费用:%f元\n", charge);}}