列表

详情


JAVA34. 求绝对值,平方根,对数,正弦值

描述

编写函数求出任意数的绝对值,平方根,对数,正弦值

输入描述

任意数字

输出描述

任意数的绝对值,平方根,对数,正弦值(请直接使用Math类的方法进行运算,不考虑精度问题)

示例1

输入:

4

输出:

4.0
2.0
1.3862943611198906
-0.7568024953079282

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Java 解法, 执行用时: 36ms, 内存消耗: 11516KB, 提交时间: 2021-11-04

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        double num = scanner.nextDouble();

        //write your code here......
        System.out.println(Math.abs(num));
        System.out.println(Math.sqrt(num));
        System.out.println(Math.log(num));
        System.out.println(Math.sin(num));
    }
}

Java 解法, 执行用时: 36ms, 内存消耗: 12100KB, 提交时间: 2021-11-18

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        double num = scanner.nextDouble();

        //write your code here......
         System.out.println(Math.abs(num));
           System.out.println(Math.sqrt(num));
              System.out.println(Math.log(num));
              System.out.println(Math.sin(num));
    }
}

Java 解法, 执行用时: 36ms, 内存消耗: 12188KB, 提交时间: 2021-11-24

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        double num = scanner.nextDouble();

        //write your code here......
         System.out.println(Math.abs(num));
         System.out.println(Math.sqrt(num));
         System.out.println(Math.log(num));
         System.out.println(Math.sin(num));
        
        

    }
}

Java 解法, 执行用时: 37ms, 内存消耗: 11720KB, 提交时间: 2021-11-23

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        double num = scanner.nextDouble();


        System.out.println(Math.abs(num));
        System.out.println(Math.sqrt(num));
        System.out.println(Math.log(num));
        System.out.println(Math.sin(num));
    }
    }

Java 解法, 执行用时: 37ms, 内存消耗: 11976KB, 提交时间: 2021-11-17

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        double num = scanner.nextDouble();

        //write your code here......
        System.out.println(Math.abs(num)+"\n"+Math.sqrt(num)+"\n"+Math.log(num)+"\n"+Math.sin(num));
    }
}

上一题