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

Lalala

Uploaded by

amana.firdaus123
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)
52 views5 pages

Lalala

Uploaded by

amana.firdaus123
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

Computer

Assignme
Name:
nt
Prog.1: Write a complete Java program that invokes a
function satis() to find whether four integers a, b, c, d
sent to satis( ) satisfy the equation a3 + b3 + c3 = d3 or
not. The function satis( ) returns 0 if the above equation
is satisfied with the given four numbers otherwise it
returns -1.

import java.util.Scanner;

class CheckEqn
{
int satis(int p,
int q,
int r,
int s) {
int res;

double lhs = Math.pow(p,3)


+ Math.pow(q,3)
+ Math.pow(r,3);

double rhs = Math.pow(s,3);

if(lhs == rhs)
res = 0;
else
res = -1;

return res;
}

public static void main(String args[])


{
CheckEqn obj = new CheckEqn();

Scanner in = new Scanner(System.in);


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

int res = obj.satis(a, b, c, d);

if(res == 0)
System.out.println("Equation satisfied");
else
System.out.println("Equation not satisfied");
}
}

Prog.2: Develop a class "Array" with the following


Specifications:
instant Variables- int a[20], k
Member functions-
public void input() To input integer members to array A
and a number separately to variable k.
public void search() To find and print 'Search
Successful' if number is found 'Search Unsuccessful'
otherwise.
import java.io.*;
class Array
{
int a[] = new int[20];
int k;
public void input() {
InputStreamReader isr = new
InputStreamReader(System.in);
BufferedReader x = new BufferedReader(isr);
for(int i = 0;i<20;i++)
{
System.out.print ("Enter a number : ");
a[i] = Integer.parseInt ( x.readLine());
}
System.out.print ("Enter a No. to Search : ");
k = Integer.parseInt ( x.readLine());
}
public void search()
{
boolean flag = false;
for(int i = 0;i<20;i++)
{
if(a[i] = = k)
flag = true;
}
if(flag = = false)
System.out.println ("Number not found in Array");
else
System.out.println ("Number found in Array");
}
}
public class ques6
{
public static void main() throws IOException
{
Array a = new Array();
a.input();
a.search();
}
}

You might also like