public class first { public static void main(String[] args) { int a=5; int b=6; System.out.println("交换前:"+a+","+b); int c; c=a; a=b; b=c; System.out.println("交换后:"+a+","+b); } }
1.已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。
2.给定一个0~1000的整数,求各位数的和
import java.util.Scanner; public class first { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入1-1000的整数"); int i = sc.nextInt(); int ge=i%10; int shi=i%100/10; int bai=i%1000/100; int qian=i/1000; int sum=ge+shi+bai+qian; System.out.println(sum); } }
3.华氏度50转成摄氏度是多少?
public class first { public static void main(String[] args) { int hua=50; int she=(hua-32)*5/9; System.out.println(she); } }
4.给定一个任意的大写字母A~Z,转换为小写字母。
import java.util.Scanner; public class first { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入A-Z的大写字母"); String line = sc.nextLine(); System.out.println(line.toLowerCase()); } }