KnowledgeBoat Logo

Computer Applications

Write a program to input a number and evaluate the results based on the number entered by the user:

(a) Natural logarithm of the number

(b) Absolute value of the number

(c) Square root of the number

(d) Cube of the number

(e) Random numbers between 0 (zero) and 1 (one).

Java

Java Math Lib Methods

ICSE 2006

207 Likes

Answer

import java.util.Scanner;

public class KboatMathMethods
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Number: ");
        double n = in.nextDouble();
        
        System.out.println("Natural logarithm = " + Math.log(n));
        System.out.println("Absolute value = " + Math.abs(n));
        System.out.println("Square root = " + Math.sqrt(n));
        System.out.println("Cube root= " + Math.cbrt(n));
        System.out.println("Random number = " + Math.random());
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input a number and evaluate the results based on the number entered by the user: (a) Natural logarithm of the number (b) Absolute value of the number (c) Square root of the number (d) Cube of the number (e) Random numbers between 0 (zero) and 1 (one).

Answered By

96 Likes


Related Questions