jkk898989

导航

第一次作业

  1. 定义圆形半径,求面积。int r =4;

package mjkjkmkj;

public class njknjknkj {
    public static void main(String[] args) {
        double r = 4;
        double mian = 0;
        mian = r * r * 3.14;
        System.out.println("园的面积为" + mian);
    }

}

 

2.     华氏温度和摄氏温度互相转换,从华氏度变成摄氏度你只要减去32,乘以5再除以9就行了,将摄氏度转成华氏度,直接乘以9,除以5,再加上32即行。

3.  package mjkjkmkj;

import java.util.Scanner;

public class njknjknkj {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入(1/0)");

        System.out.println("1.输入摄氏度  2.输入华氏度"  );

        int i = sc.nextInt();

        if(i == 1) {

            System.out.println("请输入摄氏度温度:");

            double s = sc.nextDouble();

            double h = s * 9 / 5 + 32;

            System.out.println( "摄氏度"+ s + "温度转换为摄氏温度为" + h + "度");

        }

        if(i == 0) {

            System.out.println("请输入华氏温度:");

            double h = sc.nextDouble();

            double s = (h - 32) * 5 / 9;

            System.out.println( "华氏摄氏度"+ h + "温度转换为摄氏温度为" + s + "度");

        }

    }

 

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

package mjkjkmkj;

import java.util.Scanner;

public class njknjknkj {

    public static void main(String[] args) {

        int a = 3;

        int b = 8;
        int temp = 0;
        temp = a;

        a = b;
        b = temp;


        System.out.println("交换过后" + ",a =" + a + ",b =" + b);

}

}

 

4定义一个任意的5位整数,将它保留到百位,无需四舍五入(知识点:变量和运算符综合应用)

  package mjkjkmkj;

import java.util.Scanner;

public class njknjknkj {

    public static void main(String[] args) {

        int a = 23288;

        a = a /10 /10;

        System.out.println(a);

    }







}

 

 

6. 定义一个任意的大写字母A~Z,转换为小写字母(知识点:变量和运算符综合应用) 

package mjkjkmkj;

import java.util.Scanner;

public class njknjknkj {

    public static void main(String[] args) {

                Scanner reader=new Scanner(System.in);

                char c='G',x;

                x=(char)(c+32);

                System.out.println("小写字母是:"+x);

            }



    }

 

7. 输入一个任意的小写字母a~z,转换为大写字母
package mjkjkmkj;

import java.util.Scanner;

public class njknjknkj {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        char zi = s.charAt(0);

        char xzi = (char)(zi - 32);

        System.out.println(xzi);

    }





}

 

posted on 2023-06-02 22:36  _ckc  阅读(25)  评论(0编辑  收藏  举报