0% found this document useful (0 votes)
7 views11 pages

Computer HW

class notees

Uploaded by

htuthkhh
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)
7 views11 pages

Computer HW

class notees

Uploaded by

htuthkhh
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/ 11

priyangsu basu

Q1.import java.util.Scanner;

public class QuadraticEquation

public static void main()

Scanner sc= new Scanner(System.in);

System.out.println("Enter the coefficient a: ");

double a =sc.nextDouble();

System.out.println("Enter the coefficient b: ");

double b = sc.nextDouble();

System.out.println("Enter the coefficient c: ");

double c = sc.nextDouble();

double discriminant = b * b-4*a*c;


if (discriminant < 0)

System.out.println("The roots of the equation


are imaginary:");

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

double imaginaryPart = Math.sqrt(-discriminant)


/ (2 * a);

System.out.println("Root 1: " + realPart + " + "


+ imaginaryPart + "i");

System.out.println("Root 2: " + realPart + " - " +


imaginaryPart + "i");

else if (discriminant > 0)

System.out.println("The roots of the equation


are real and distinct:");

double root1 = (-b + Math.sqrt(discriminant)) /


(2 * a);

double root2 = (-b - Math.sqrt(discriminant)) / (2


* a);

System.out.println("Root 1: " + root1);

System.out.println("Root 2: " + root2);

else
{

System.out.println("The roots of the equation


are real and repeated:");

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

System.out.println("Root: " + root);

}
}
--------------------------------------------------------------------------------------------------------------------------------------
-------

Q2
import java.util.Scanner;

class LinearEquations
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of a:");
double a = sc.nextDouble();
System.out.println("Enter the value of b:");
double b = sc.nextDouble();
System.out.println("Enter the value of c:");
double c = sc.nextDouble();
System.out.println("Enter the value of d:");
double d = sc.nextDouble();
System.out.println("Enter the value of m:");
double m = sc.nextDouble();
System.out.println("Enter the value of n:");
double n = sc.nextDouble();

double denominator = a * d - c * b;
if (denominator == 0)
{
System.out.println("Error: Denominator is zero. Cannot
calculate x1 and x2.");
}
else
{
double x1 = (m * d - b * n) / denominator;
double x2 = (n * a - m * c) / denominator;
System.out.println("Value of a: " + a);
System.out.println("Value of b: " + b);
System.out.println("Value of c: " + c);
System.out.println("Value of d: " + d);
System.out.println("Value of m: " + m);
System.out.println("Value of n: " + n);
System.out.println("Value of x1: " + x1);
System.out.println("Value of x2: " + x2);
}
}
}
------------------------------------------------------------------------------------------------------------------------------

Q3 import java.util.*;
class prog3
{
public static void main();
{
Scanner sc=new Scanner(System.in);
System.out.println(“enter annual income”);
double a=sc.nextDouble();
double tax=0.0;
{
if (a<=100000)
{
tax=a;
}
else
if (a<=500000)
{
tax=1000+(a*10/100.0);
}
else
if (a<=800000)
{
tax=5000+(a*20/100.0);
}
else
{
tax=10000+(a*30/100.0);
}
System.out.println(tax);
}
}
}
--------------------------------------------------------------------------------------------
----------------

Q4 import java.util.*;
class prog 4
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“enter a no”);
double a=sc.nextDouble();
{
double log=Math.log(a);
double abs=Math.abs(a);
double sqrt=Math.sqrt(a);
double random=Math.random();
}
System.out.println(“logarithm”+log);
System.out.println(“absolute no”+abs);
System.out.println(“square root”+sqrt);
System.out.println(“random no”+random);
}
}
--------------------------------------------------------------------------------------------
-------------------------

5. import java.util.*;
class cal
{
public static void main();
{
Scanner sc=new Scanner(System.in);
System.out.println(“enter dist”);
double d=sc.nextDouble();
amount=0.0;
{
if (d<5)
{
amount = 15.0;
}
else
if (d<=20)
{
amount=50.0;
}
else
if (d<=50)
{
amount=100.0;
}
System.out.println(amount);
}
}
}
--------------------------------------------------------------------------------------------
------------
import java.util.*;
class cal
{
public static void main(int x,int y);
{
if (x>0)
System.out.println(4*x+y);
else
if (x<=0)
System.out.println(4*x-y);
}
}
--------------------------------------------------------------------------------------------
-

You might also like