You are on page 1of 4

Lab # 03

Task 1: To calculate the area and circumference of circle by giving the value of radius
through commandline in meter use math functions where needs.

import java.util.Scanner;

class task31

static Scanner sc = new Scanner(System.in);

public static void main(String args[])

System.out.print("Enter the radius:");

double radius = sc.nextDouble();

double area = Math.PI*(radius*radius);

System.out.println("The area of the circle is:"+area);

double circumference = Math.PI*2*radius;

System.out.println("The circumference of the circle is:"+circumference);

Task 2: To solve the quadratic equation and display the two real roots x1 and x2. The three
inputswill be given through command line use math functions where needs.

import java.util.Scanner;

class task32

public static void main(String args[])

Scanner input = new Scanner(System.in);

System.out.print("Enter the value of a:");

double a = input.nextDouble();

System.out.print("Enter the value of b:");


double b = input.nextDouble();

System.out.print("Enter the value of c:");

double c = input.nextDouble();

double det = (b*b)-(4*a*c);

if(det>0)

double root1 = (-b+Math.pow(det,0.5))/(2.0*a);

double root2 = (-b-Math.pow(det,0.5))/(2.0*a);

System.out.println("The roots are"+root1+"and"+root2);

else if(det==0)

double root1=-b/(2*a);

System.out.println("the root is"+root1);

else

double real = -b/(2*a);

double imaginary = (-b+Math.pow(-det,0.5))/(2.0*a);

System.out.format("root1=%.2f+%.2fi",real,imaginary);

System.out.format("\nroot2=%.2f-%.2fi",real,imaginary);

Task 3: To roll a dice and generate a general number from 1 to 6 and display that random
numberuse math functions where needs.
import java.util.Random;

class task33

{
public static void main(String args[])

Random dice=new Random();

int number;

for(int counter=1;counter<=10;counter++)

number=1+dice.nextInt(6);

System.out.println(number+ "");

Task 4: To Find the following Angle Functions using Math functions collected input from user
byCommand Line Input ( Sin(), Cos(), Tan(), )

import java.util.Scanner;

class task34

static Scanner sc = new Scanner(System.in);

public static void main(String args[])

System.out.print("Enter the value of angle in degrees");

double degrees = sc.nextDouble();

System.out.println("Calculation of sin,cos,tan of angle");

double sineofangle = Math.sin(degrees);

double cosofangle = Math.cos(degrees);

double tanofangle = Math.tan(degrees);

System.out.println();

System.out.println("The sine of "+degrees+"degrees is:"+sineofangle);

System.out.println("The cos of "+degrees+"degrees is:"+cosofangle);


System.out.println("The tan of "+degrees+"degrees is:"+tanofangle);

System.out.println();

System.out.println("Calculation of cosec,sec,cot of angle");

double cosecofangle =1/Math.sin(degrees);

double secofangle = 1/Math.cos(degrees);

double cotofangle = 1/Math.tan(degrees);

System.out.println();

System.out.println("\nThe cosec of "+degrees+"degrees is:"+cosecofangle);

System.out.println("The sec of "+degrees+"degrees is:"+secofangle);

System.out.println("The cot of "+degrees+"degrees is:"+cotofangle);

System.out.println();

You might also like