The Icse CH 6 Solution
The Icse CH 6 Solution
1. Write a program to input two numbers in Java and print the square root and cube root of both.
Ans.
import java.util*;
class SquareandCube
{
public static void main (String args[])
{
Scanner in = new Scanner(System.in);
int n;
System.out.println ("Enter the number");
n = in.nextInt();
System.out.println("Square root="+Math.sqrt(n));
System.out.println("Cube root="+Math.cbrt(n));
}
}
2. Write a program to input four numbers and print the biggest among them (use Math.max( )).
Ans.
import java.util.*;
class BiggestNumber
{
public static void main(String args[])
{
Scanner in = new Scanner( System.in);
int a,b,c,d,g;
System.out.println("Enter the first number");
a=in.nextInt();
System.out.println("Enter the second number");
b=in.nextInt();
System.out.println("Enter the third number");
c=in.nextInt();
System.out.println("Enter the fourth number");
d=in.nextInt();
System.out.println("Enter the biggest number");
g=in.nextInt();
g=Math.max(a,b,c);
g=Math.max(g,d);
System.out.println(“Biggest number=”+g);
}
}
3. Rohan wants to find the ceil and floor value of a variable. Which methods from the Math class should he use to
find the same.
Ans.
import java.util.*;
class math_operations
{
public static void main (String args[]);
{
Scanner in = new Scanner (System.in);
int a,b;
System.out.println("Enter the number");
a = in.nextInt();
b = in.nextInt();
System.out.println("Math.ceil(a,b))";
System.out.println("Math.floor(a,b))";
}
}
4. Priya'steacher has given her an assignment to write a program to calculate the surface area of a cylinder using
Math functions. Help her in doing so.
Ans.
import java.util.*;
class cylinder
{
public static void main (String args[]);
{
Scanner in = new Scanner (System.in);
double r,h,s;
System.out.println("Enter the radius");
r = in.nextDouble();
System.out.println("Enter the height");
h = in.nextDouble();
s = ((2.0*22.0/7.0)*(r*h))+2.0*22.0/7.0(Math.sqrt(2));
System.out.println(“Surface area of cylinder=”+s);
}
}