You are on page 1of 4

Department of computer science & Info-Technology (CS & IT)

Lab Task#1

BSSE-8th-A

Course: OOP

Iqra Saeed
Task 1:

Create a simple java program to print hello world

public class labtask1 {


public static void main (String []args)
{
System.out.print("hello world");

}
}

task 2

Create a calculator class and add methods of addition, multiplication, division


and

subtraction.
package labtask1;
import java.util.Scanner;
public class calculator {

public static void main(String[]args)


{
int c;
System.out.println("Add the number press 1");
System.out.println("Multi the number press 2");
System.out.println("Sub the number press 3");
System.out.println("divi the number press 4");
Scanner a=new Scanner(System.in);
int x=a.nextInt();

if(x==1)
{
System.out.println("Enter the value");
int y=a.nextInt();
int z=a.nextInt();
c=y+z;
System.out.println("Add="+c);

}
else if(x==2)
{
System.out.println("Enter the value");
int y=a.nextInt();
int z=a.nextInt();
c=y*z;
System.out.println("Multi="+c);

}
else if(x==3)
{
System.out.println("Enter the value");
int y=a.nextInt();
int z=a.nextInt();
c=y-z;
System.out.println("Sub="+c);

}
else if(x==4)

{
System.out.println("Enter the value");
int y=a.nextInt();
int z=a.nextInt();
c=y/z;
System.out.println("Divi="+c);

}
else
{
System.out.println("Invaild Value");

}
}
}

You might also like