1.已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。
package zzz; public class ccc { public static void main(String[] args) { // TODO Auto-generated method stub int a=100; int b=200; int c; c=a; a=b; b=c; System.out.println("交换后的a:"+ a + ",b:"+b); } }
2.给定一个0~1000的整数,求各位数的和,例如345的结果是3+4+5=12。
package zzz; public class yyy { public static void main(String[] args) { int a=345; int b, c, d, sum; b = a/100; c = a/10%10; d = a%10; sum = b +c +d; System.out.println("结果为" + sum); } }
3.华氏度50转成摄氏度是多少?
package zzz; public class Y { public static void main(String[] args) { // TODO Auto-generated method stub float c=50.0f; float f=113.0f; float cTof=(f-32)*5/9; float fToc=c*9/5+32; System.out.println("摄氏华氏度="+cTof); System.out.println("华氏摄氏度="+fToc); } }
4.给定一个任意的大写字母A~Z,转换为小写字母。
package zzz; public class D { public static void main(String[] args) { char c='A'; System.out.println((char)(c=32)); } }