java第二次作业
1.编写一个程序,定义圆的半径,求圆的面积.
package exe2; public class text3 { public static void main(String[] args) { // TODO Auto-generated method stub double r=3.0; double area=r*r*3.14; System.out.println("圆的面积="+area); } }
2.华氏温度和摄氏温度互相转换
package exe2; public class text { public static void main(String[] args) { // TODO Auto-generated method stub double hua=50,she=30; double she1=(hua-32)*5/9; double hua1=she*9/5+32; System.out.println(she1); System.out.println(hua1); } }
3.已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。
package exe2; public class text2 { public static void main(String[] args) { // TODO Auto-generated method stub int a=5,b=8,c; c=a; a=b; b=c; System.out.println("交换后的a:"+ a + ",b:" + b); } }
4.定义一个任意的5位整数,将它保留到百位,无需四舍五入
package exe2; public class text4 { public static void main(String[] args) { // TODO Auto-generated method stub int a=12345; int baiwei=(a/100)*100; System.out.println(baiwei); } }
5.输入一个0~1000的整数,求各位数的和
package exe2; public class text5 { public static void main(String[] args) { int zhengshu=234,sum; sum=(zhengshu%10)+(zhengshu%100/10)+(zhengshu%1000/100); System.out.println(sum); // TODO Auto-generated method stub } }
6.定义一个任意的大写字母A~Z,转换为小写字母
定义一个任意的小写字母a~z,转换为大写字母
package exe2; public class text6 { public text6() { // TODO Auto-generated constructor stub } public static void main(String[] args) { char daxie,xiaoxie,shuchu; daxie='A'; shuchu=(char) (daxie+32); System.out.println(shuchu); xiaoxie='a'; shuchu=(char) (xiaoxie-32); System.out.println(shuchu); // TODO Auto-generated method stub } }