/*1、已知a,b均是整型變量说墨,寫出將a,b兩個變量中的值互換的程序骏全。(知識點:變量和運算符綜合應(yīng)用*/
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的整數(shù),求各位數(shù)的和吟温,例如345的結(jié)果是3+4+5=12注:分解數(shù)字既可以先除后模也可以先模后除(知識點:變量和運算符綜合應(yīng)用)*/
public class Sum6 {
public static void main(String[] args) {
int d = 856;
System.out.println("原始數(shù)據(jù):" + d + "百位是:" + d / 100 + "十位是:" + d % 100 / 10 + "個位是:" + d % 10 + "位數(shù)總和是:"
+ (d / 100 + d % 100 / 10 + d % 10));
}
}
運行圖:
/*3突颊、華氏溫度和攝氏溫度互相轉(zhuǎn)換鲁豪,從華氏度變成攝氏度你只要減去32,乘以5再除以9就行了律秃,將攝氏度轉(zhuǎn)成華氏度爬橡,直接乘以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糙申,轉(zhuǎn)換為小寫字母。*/
public class ChangeA {
public static void main(String[] args) {
char g = 'A';
System.out.println("原來的字符是:" + g + "轉(zhuǎn)換成小寫是:" + (char) (g + 32));
}
}
運行圖: