3.19 第一次上级作业

1、已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。(知识点:变量和运算符综合应用)

 1 package text;
 2 
 3 public class note1 {
 4     public static void main(String[] args) {
 5         int a = 10;
 6         int b = 20;
 7         int tmp;
 8         //进行数据交换
 9         tmp = a;
10         a = b;
11         b = tmp;
12         System.out.println("交换后的a:"+ a + ",b:" + b);
13     }
14 
15 }

2、给定一个01000的整数,求各位数的和,例如345的结果是3+4+512注:分解数字既可以先除后模也可以先模后除(知识点:变量和运算符综合应用)

 1 package text;
 2 
 3 public class note1 {
 4     public static void main(String[] args) {
 5         int a =275 ;
 6         int b, c, d, e, sum;
 7         e = a /1000;
 8         b = a / 100 % 10;
 9         c = a  / 10 % 10;
10         d = a % 10;
11         sum = b +c +d ;
12         System.out.println("结果为" + sum);
13     }
14 
15 }

3、华氏度50转成摄氏度是多少???(华氏温度和摄氏温度互相转换,从华氏度变成摄氏度你只要减去32,乘以5再除以9就行了,将摄氏度转成华氏度,直接乘以9,除以5,再加上32即行)

 1 package text;
 2 
 3 public class note1 {
 4     public static void main(String[] args) {
 5          int Fahrenehit=50;
 6          int Celsius=(Fahrenehit-32)*5/9;
 7         System.out.println(" Fahrenehit 50 is "+ Celsius + " Celsius");
 8     }
 9 
10 }

4、给定一个任意的大写字母A~Z,转换为小写字母。 (知识点:变量和运算符)

 1 package text;
 2 
 3 public class note1 {
 4     public static void main(String[] args) {
 5         char ch = 'A';
 6         System.out.println((char)(ch+32));
 7 
 8     }
 9 
10 }

原文地址:https://www.cnblogs.com/gwz-1314/p/12523350.html