Skip to main content

13.interface

File: /home/student/saiesh/ADS/Assignment No 13/ads13_2A.java
package pack;
interface ip
{
public
public
public
public
}
void
void
void
void
add(int
sub(int
mul(int
div(int
a,
a,
a,
a,
int
int
int
int
b);
b);
b);
b);
public class A implements ip
{
public void add(int a, int b)
{
System.out.println("Addition is\t\t: "+(a+b));
}
public void sub(int a,int b)
{
System.out.println("Substraction is\t\t: "+(a-b));
}
public void mul(int a, int b)
{
System.out.println("Multiplication is\t: "+(a*b));
}
public void div(int a, int b)
{
System.out.println("Division is\t\t: "+(a/b));
}
}
Page 1 of 1

.......................

File: /home/student/saiesh/ADS/Assignment No 13/ads13_2B.java
package mypack;
import pack.*;
import java.util.Scanner;
public class B
{
public static void main(String arg[])
{
A obj= new A();
Scanner sc=new Scanner(System.in);
System.out.println("\nEnter first number\t: ");
int a=sc.nextInt();
System.out.println("\nEnter second number\t: ");
int b=sc.nextInt();
obj.add(a,b);
obj.sub(a,b);
obj.mul(a,b);
obj.div(a,b);
}
}
/*
OUTPUT
[saiesh@saiesh ~]$ javac -d . A.java
[saiesh@saiesh ~]$ javac -d . B.java
[saiesh@saiesh ~]$ java mypack.B
Enter first number
: 5
Enter second number
: 5
Addition is
Substraction is
Multiplication is
Division is
[saiesh@saiesh ~]$ */
:
:
:
:
10
0
25
1
Page 1 of 1

Comments

Popular posts from this blog

PPL 1

NEW Unit III STRUCTURING OF PROGRAM MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of ‘Data Abstraction’? (a) Reduce Complexity (b) Binds together code and data (c) Parallelism (d) None of the mentioned Answer : a Explanation : An essential element of Object Oriented Programming is ‘Data Abstraction’ which means hiding things. Complexity is managed through abstraction. 2. Which of the following mechanisms is/are provided by Object Oriented Language to implement Object Oriented Model? (a) Encapsulation (b) Inheritance (c) Polymorphism (d) All of the mentioned Answer : d Explanation : None. 3. Which of these is the functionality of ‘Encapsulation’? (a) Binds together code and data (b) Using single interface for general class of actions. (c) Reduce Complexity (d) All of the mentioned Answer : a Explanation : ‘Encapsulation’ acts as protective wrapper that prevents code and data from being accessed by other code defined outside the...

replacing strings without using inbuild functions

 Q:replacing strings without using inbuild functions. We are using gcc compiler and terminal to compile the code and ubuntu OS. PROGRAM: #include<stdio.h> int strln1(char s1[]); int strln2(char s2[]); void strcpy1(char s1[],char s2[]); int main() {     char s1[30],s2[30];     int result1,result2;     printf("Enter the string s1");     scanf("%s",s1);     printf("Enter the string s2");     scanf("%s",s2);     printf("Your string s1 is %s",s1);     printf("\nYour string s2 is %s",s2);     result1=strln1(s1);     result2=strln2(s2);     printf("\nlength of string s1 is %d\n",result1);     printf("\nlength of string s2 is %d\n",result2);     strcpy1(s1,s2); } int strln1(char s1[]) {     int i,ln;   ...

create a program to print directory strucure like C:\cygwin\home\administrator.

Q: Create a program that uses escape sequence \\ to print the following directory structure C:\cygwin\home\administrator. We are using gcc compiler and terminal to compile the code and ubuntu OS.   PROGRAM: #include<stdio.h> void main()  {   printf("C:\\cygwin\\home\\administrator.\n");  }  OUTPUTE: