[go: up one dir, main page]

0% found this document useful (0 votes)
10 views5 pages

std 9 Chapter 6 Mathematical Library Methods - Programs

The document contains a series of Java programming exercises focused on mathematical operations, including finding the greatest and smallest of three numbers, calculating the hypotenuse of a triangle, evaluating various mathematical functions, computing average marks, and determining the radius of a circle from its area. Each exercise includes sample code, inputs, and expected outputs. The programs utilize Java's Math library for various calculations.

Uploaded by

Hemashree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

std 9 Chapter 6 Mathematical Library Methods - Programs

The document contains a series of Java programming exercises focused on mathematical operations, including finding the greatest and smallest of three numbers, calculating the hypotenuse of a triangle, evaluating various mathematical functions, computing average marks, and determining the radius of a circle from its area. Each exercise includes sample code, inputs, and expected outputs. The programs utilize Java's Math library for various calculations.

Uploaded by

Hemashree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter 6

Mathematical Library Methods

Unsolved Java Programs

Question 1

Write a program in Java to input three numbers and display the greatest and the
smallest of the two numbers.
Hint: Use Math.min( ) and Math.max( )
Sample Input: 87, 65, 34
Sample Output: Greatest Number 87
Smallest number 34

import java.util.Scanner;

public class GreatestNumber


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter First Number: ");


int a = in.nextInt();
System.out.print("Enter Second Number: ");
int b = in.nextInt();
System.out.print("Enter Third Number: ");
int c = in.nextInt();

int g = Math.max(a, b);


g = Math.max(g, c);

int s = Math.min(a, b);


s = Math.min(s, c);

System.out.println("Greatest Number = " + g);


System.out.println("Smallest Number = " + s);
}
}

Output
Question 2

Write a program in Java to calculate and display the hypotenuse of a Right-Angled


Triangle by taking perpendicular and base as inputs.
Hint: h = √p2 + b2

import java.util.Scanner;

public class Hypotenuse


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Perpendicular: ");
double p = in.nextDouble();
System.out.print("Enter Base: ");
double b = in.nextDouble();

double h = Math.sqrt(Math.pow(p, 2) + Math.pow(b, 2));

System.out.println("Hypotenuse = " + h);


}
}

Output

Question 3

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).

import java.util.Scanner;

public class MathMethods


{
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());
}
}

Output

Question 4

In an examination, you have appeared for three subjects i.e. Physics, Chemistry and
Biology. Write a program in Java to calculate the average mark obtained and finally
display the marks in rounded-off form.
Take Physics, Chemistry. and Biology marks as inputs.

import java.util.Scanner;

public class AvgMarks


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter Marks");
System.out.print("Physics: ");
int p = in.nextInt();
System.out.print("Chemistry: ");
int c = in.nextInt();
System.out.print("Biology: ");
int b = in.nextInt();

double avg = (p + c + b) / 3.0;


long roundAvg = Math.round(avg);

System.out.println("Rounded Off Avg Marks = " +


roundAvg);
}
}

Output

Question 5

You want to calculate the radius of a circle by using the formula:


Area = (22/7) * r2; where r = radius of a circle
Hence the radius can be calculated as:
r = √((7 * area) / 22)
Write a program in Java to calculate and display the radius of a circle by taking area as
an input.

import java.util.Scanner;

public class CircleRadius


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Area of Circle: ");
double area = in.nextDouble();
double r = Math.sqrt(7 * area / 22);
System.out.print("Radius of Circle = " + r);
}
}

Output

You might also like