第一次上机作业
1、已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。
package lsiyn; public class Text1 { public static void main(String[] args) { // TODO Auto-generated method stub int a=100; int b=200; int tmp; tmp=a; a=b; b=tmp; System.out.println(a); System.out.println(b); } }
2..给定一个0~1000的整数,求各位数的和
package lsiyn; public class Text1 { public static void main(String[] args) { // TODO Auto-generated method stub int a =218; 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、华氏度50转成摄氏度是多少?
package lsiyn; public class Text1 { public static void main(String[] args) { // TODO Auto-generated method stub double n=50; double f; f=(n-32)*5/9; System.out.println("转成摄氏度的值是:"+f); } }
4、给定一个任意的大写字母A~Z,转换为小写字母。
package lsiyn; public class Text1 { public static void main(String[] args) { // TODO Auto-generated method stub char c='F'; if(c>='A' && c<='Z'){ c+=32; System.out.println(c); } } }