第二次作业

1.  定义圆的半径,求圆面积

import java.util.Scanner;


public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int r=2;
        double s=3.14*r*r;
        System.out.println("圆面积为"+s);
        
       
    }

}

 

2.华氏度摄氏度的转换

import java.util.Scanner;


public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        float C;
        float F=in.nextInt();
        C=(F-32)*5/9;
        System.out.println("摄氏度为"+C);
        
        
    }

}

import java.util.Scanner;


public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        float F;
        float C=in.nextInt();
        F=C*9/5+32;
        System.out.println("华氏度为"+F);
        
        
    }

}

 

3.a,b两个变量中的值互换

import java.util.Scanner;


public class Test {

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

}

 

4.将五位整数保留到百位

import java.util.Scanner;


public class Test {

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

}

 

5.求各位数的和

import java.util.Scanner;


public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a=685;
        int ge=a%10;
        int shi=a%100/10;
        int bai=a/100;
        int sum=ge+shi+bai;
        System.out.println("各位数的和为"+sum);
       
    }

}

 

6.大写小写字母转换

import java.util.Scanner;


public class Test {

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

}

 

posted @ 2021-03-12 09:40  刘源丰  阅读(46)  评论(0编辑  收藏  举报