目录
05:为抵抗洪水,战士连续作战89小时,编程计算共多少天零多少小时?
09:小明要到美国旅游,可是那里的温度是以华氏度为单位记录的。它需要一个程序将华氏温度(80度)转换为摄氏度,并以华氏度和摄氏度为单位分别显示该温度。
byte short int long float double char boolean
final byte A =1 ; final short B=1:
final int C=1; final long D=1;
final float E =1.1 ;final double F=1.23
final char G =’a’; final Boolean H=true
- public class Demo1 {
- public static void main(String [] args){
- int num1=10;
- int num2=20;
- int a=num1+num2;
- int b=num1-num2;
- int c=num1/num2;
- int d=num1*num2;
- int e=num1%num2;
- System.out.println(num1+"+"+num2+"="+a);
- System.out.println(num1+"-"+num2+"="+b);
- System.out.println(num1+"/"+num2+"="+c);
- System.out.println(num1+"*"+num2+"="+d);
- System.out.println(num1+"%"+num2+"="+e);
- }
- }
- public class Demo4 {
- public static void main(String[] args) {
-
- char a = 'a';
- char b = 'b';
-
- System.out.println(a+b);
- System.out.println(a-b);
- System.out.println(a*b);
- System.out.println(a/b);
-
- }
- }
- Public class Demo2{
- public static void main(String [] args){
- int day=89/24;
- int hours=89%24;
- System.out.println("总计"+day+"天"+hours+"小时");
- }
- }
提示:摄氏度与芈氏度的转换公式为:摄氏度 = 5/9.0*(华氏度-32)
- public class Demo3 {
- public static void main(String [] args){
- double centigrade;
- double degree=80;
- centigrade=5/9.0*(degree-32);
- System.out.println("华氏温度:"+degree+"摄氏度"+centigrade);
- }
- }
-