Computer HW
Computer HW
Q1.import java.util.Scanner;
double a =sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
else
{
}
}
--------------------------------------------------------------------------------------------------------------------------------------
-------
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);
}
}
--------------------------------------------------------------------------------------------
-