Java第一次上机作业

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

public class circle {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
      double a = 3;
      double s = a*a*3.14;
      System.out.println(s);
    }

}

2.温度和摄氏温度互相转换

public class tem {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
            double hua = 50;
            double hua1 = hua-32;
            double she = hua1*5/9;
            double she1 = 30*9/5;
            double hua2 = she1+32;
            System.out.println(she);
            System.out.println(hua2);
    }

}

3.已知a,b均是整型变量,写出a,b两个变量中的值互换的程序。

public class huhuan {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
      int a=5,b=8,c;
      c=b;
      b=a;
      a=c;
      System.out.println("a=" +a);
      System.out.println("b=" +b);
    }

}

4.定义一个任意的五位整数,将它保留到百位,无需四舍五入。

public class baoliu {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
      int n=12345;
      int a;
      a=n/100*100;
      System.out.println(a);
    }
}

5.输入一个0~1000的整数,求各位数的和。

import java.util.*;
public class qiuhe {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
         System.out.println("请输入一个1~1000的整数:");
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            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);
    }

}

6.定义一个任意的大写字母A-Z,转化为小写字母。

public class zhuanhuazimu {

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

}

posted @ 2021-03-12 12:22  柳云倩  阅读(67)  评论(0编辑  收藏  举报