Programming Examples

Java program that outputs the results of the following evaluations based on the number entered by the user


Write a program that outputs the results of the following evaluations based on the number entered by the user.

i. Cube root of the number

ii. Absolute value of the number

iii. Square root of the number

iv. Random numbers between 0 and 1.

Solution

import java.util.*;
class MathFun
{
	public static void main(String arr[])
	{
		double n,c,a,s,r;
		Scanner sc=new Scanner(System.in);
		System.out.println(“Enter a number:”);
		n=sc.nextDouble();
		c=Math.cbrt(n);
		a=Math.abs(n);
		s=Math.sqrt(n);
		r=Math.random();
		System.out.println(“Cube Root=”+c);
		System.out.println(“Absolute=”+a);
		System.out.println(“Square Root=”+s);
		System.out.println(“Random number=”+r);
	}
}
Output

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz