JAVA第二次作业

作业1.编写一个程序,定义圆的半径,求圆的面积.

package work_oc; import java.util.Scanner; public class work_1 { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("请输入圆的半径(r>0)"); Scanner si=new Scanner(System.in); float r=si.nextFloat() float s; s=r*r*3.14F; System.out.println("该圆的半径为:"+s); } }

 

作业2.华氏温度和摄氏温度互相转换

package work_oc;

public class work_2 {

public static void main(String[] args) {
// TODO Auto-generated method stub
double hua=50;
hua=(hua-32)*5/9;
double she=30;
she=she*9/5+32;
System.out.println("50度华氏温度转化为摄氏度的结果为:"+hua);
System.out.println("30度摄氏温度转化为华氏度的结果为:"+she);
}
}

 

 

作业3.:变量和运算符综合应用

package work_oc;

public class work_3 {

public static void main(String[] args) {
// TODO Auto-generated method stub
int a=5;
int b=8;
int c;
System.out.println("交换前a,b的值分别为"+a+"和"+b);
c=a;
a=b;
b=c;
System.out.println("交换后a,b的值分别为"+a+"和"+b);
}

}

 

 

作业4.变量和运算符综合应用
package work_oc;

public class work_4 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int n=12141;
        System.out.println("五位数为:"+n);
        int a;
        a=n-(n%100);
        System.out.println("保留至百位后:"+a);
    }

}

 

 

作业5.变量和运算符综合应用
package work_oc;

public class work_5 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a=1234;
        System.out.println("其各位数总和为\n");
        int b,c,d,e;
        b=a/1000;
        e=a%10;
        c=a/100-b*10;
        d=(a%100-e)/10;
        System.out.println(b+c+d+e);
    }

}

 

 

作业6.变量和运算符综合应用
package work_oc;

public class work_6 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int field='A';
        System.out.println("其小写为");
        field=field+32;
        System.out.println((char)field);
    }

}

 

posted @ 2021-03-14 23:01  韩式小火锅  阅读(52)  评论(0编辑  收藏  举报