Java第二周作业
1.编写一个程序,定义圆的半径,求圆的面积.
package homework2; public class Text1 { /** * @param args */ public static void main(String[] args) { int r=1; double area; area=3.14*r*r; System.out.println(area); } }
2.华氏温度和摄氏温度互相转换
package homework2; public class Text2 { /** * @param args */ public static void main(String[] args) { double hua,she; hua=50; she=(hua-32)*5/9.0; System.out.println(she); she=30; hua=she*9.0/5+32; System.out.println(hua); } }
3.已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序
package homework2; public class Text3 { /** * @param args */ public static void main(String[] args) { int a=5; int b=8,c; c=a; a=b; b=c; System.out.println("a:"+a+"\nb:"+b); } }
4.定义一个任意的5位整数,将它保留到百位,无需四舍五入
package homework2; public class Text4 { /** * @param args */ public static void main(String[] args) { int a=12345,b; b=a/100*100; System.out.println(b); } }
5.输入一个0~1000的整数,求各位数的和
package homework2; public class Text5 { /** * @param args */ public static void main(String[] args) { int a=123,sum; sum=(a%10)+(a%100/10)+(a%1000/100); System.out.println(sum); } }
6.定义一个任意的大写字母A~Z,转换为小写字母
package homework2; public class Text6 { /** * @param args */ public static void main(String[] args) { char captial,result; captial='A'; result=(char) (captial+32); System.out.println(result); } }