1.
package test;
public class demo{
public static void main(String[] args) {
int a = 100;
int b = 200;
int tmp;
//进行数据交换
tmp = a;
a = b;
b = tmp;
System.out.println("交换后的a:"+ a + ",b:" + b);
}
}
2.
package test;
import java.util.*;
public class demo{
public static void main(String[] args) {
//一个三位数整数,求各位整数的和
System.out.println("请输入一个1~1000的整数:");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b, c, d, e, sum;
e = a / 1000;
b = a / 100 % 10;
c = a / 10 % 10;
d = a % 10;
sum = b +c +d +e;
System.out.println("结果为" + sum);
}
}
3.
package test;
import java.util.Scanner;
public class demo{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int fatrenheit;//输入一个华氏温度
System.out.println("输入一个华氏度:");
fatrenheit=in.nextInt();
//转换为华氏温度
int celsius =(fatrenheit-32)*5/9;
//输出结果
System.out.println(fatrenheit+"华氏度是"+celsius+"摄氏度");
}
}
4.
package test;
import java.util.*;
public class demo{
public static void main(String[] args) {
System.out.println("输入一个大写字母:");
Scanner sc = new Scanner(System.in);
String c = sc.next();
char a = c.charAt(0);
System.out.println("小写字母为"+(char)(int)(a+32));
}
}