Java第一次上机作业

1、已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序。(知识点:变量和 运算符综合应用)
public class L {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a=1;
        int b=2;
        int c=a;
        a=b;
        b=c;
        System.out.println("交换后a的值:"+a);
        System.out.println("交换后b的值:"+b);    

    }

}

 2.给定一个0~1000的整数,求各位数的和

public class L {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a = 1234;
        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转成摄氏度是多少?

public class L {

     public static void main(String[] args) {
            // TODO Auto-generated method stub
            //定义一个华氏度
            int a=50;
            //定义一个摄氏度
            int b=(a-32)*5/9;
            System.out.println("摄氏度="+b);
    }
}

 4.给定一个任意的大写字母A~Z,转换为小写字母。

public class L {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        char a = 'A';
        System.out.println((char)(a + 32)); 
    }
}

原文地址:https://www.cnblogs.com/Lucky-M/p/12525817.html