/*1、已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。(知识点:变量和运算符综合应用*/
public class Change {
public static void main(String[] args) {
int a = 3;
int b = 4;
int c = 0;
System.out.println("原来的值:" + "a=" + a + "b=" + b);
c = a;
a = b;
b = c;
System.out.println("a=" + a + "b=" + b);
}
}
运行图:
/*2.给定一个0~1000的整数,求各位数的和,例如345的结果是3+4+5=12注:分解数字既可以先除后模也可以先模后除(知识点:变量和运算符综合应用)*/
public class Sum6 {
public static void main(String[] args) {
int d = 856;
System.out.println("原始数据:" + d + "百位是:" + d / 100 + "十位是:" + d % 100 / 10 + "个位是:" + d % 10 + "位数总和是:"
+ (d / 100 + d % 100 / 10 + d % 10));
}
}
运行图:
/*3、华氏温度和摄氏温度互相转换,从华氏度变成摄氏度你只要减去32,乘以5再除以9就行了,将摄氏度转成华氏度,直接乘以9,除以5,再加上32即行*/
public class Temperature {
public static void main(String[] args) {
int e = 82;
int f = 28;
System.out.println("华氏度是:" + e + "摄氏度是:" + (e - 32) * 5 / 9);
System.out.println("摄氏度是:" + f + "华氏度是:" + (f * 9 / 5 + 32));
}
}
运行图:
/*4.给定一个任意的大写字母A~Z,转换为小写字母。*/
public class ChangeA {
public static void main(String[] args) {
char g = 'A';
System.out.println("原来的字符是:" + g + "转换成小写是:" + (char) (g + 32));
}
}
运行图: