0% found this document useful (0 votes)
48 views7 pages

Java Lab Programs for Basic Operations

The document describes 5 Java programs that perform basic math operations and input/output. Program 1 adds two hardcoded numbers. Program 2 adds two numbers input dynamically from the user. Program 3 multiplies two numbers input from the user. Program 4 divides two numbers input from the user. Program 5 takes a name input from the user and displays it.

Uploaded by

kausar4u
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views7 pages

Java Lab Programs for Basic Operations

The document describes 5 Java programs that perform basic math operations and input/output. Program 1 adds two hardcoded numbers. Program 2 adds two numbers input dynamically from the user. Program 3 multiplies two numbers input from the user. Program 4 divides two numbers input from the user. Program 5 takes a name input from the user and displays it.

Uploaded by

kausar4u
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Week -1

Lab Programs

1. // Addition of Two Numbers

public class LabOne1


{
public int first;
public int second;
String name;
public static void main(String [] args)
{
LabOne1 lo = new LabOne1();
[Link]=20;
[Link] = 10;
[Link]([Link]+[Link]);
}
}
OUTPUT:

2. // Dynamic Addition of two Numbers

import [Link];
public class LabOne2
{
public int first,second;
String name;
public static void main(String[]args)
{
LabOne2 lo = new LabOne2();
Scanner s = new Scanner([Link]);
[Link]("Enter First Number:");
[Link] = [Link]();
[Link]("Enter Second Number:");
[Link] = [Link]();
[Link]("Addition of two numbers is:" + ([Link]+[Link]));
}
}
OUTPUT:

3. // Dynamic Multiplication

import [Link];
public class LabOne3
{
int a,b;
public static void main(String[]args)
{
LabOne3 lo = new LabOne3();
Scanner s = new Scanner([Link]);
[Link]("Enter first Number:");
lo.a = [Link]();
[Link]("Enter Second Number:");
lo.b = [Link]();
[Link]("Multiplication is:"+ lo.a*lo.b);
}
}
OUTPUT:

4. // Dynamic Division

import [Link];
public class LabOne4
{
double a,b;
public static void main(String[]args)
{
LabOne4 lo = new LabOne4();
Scanner s = new Scanner([Link]);
[Link]("Enter first Number:");
lo.a = [Link]();
[Link]("Enter Second Number:");
lo.b = [Link]();
[Link]("Multiplication is:"+ lo.a/lo.b);
}
}
OUTPUT:

5. // Dynamic Name Display


import [Link];
public class LabOne5
{
public static void main(String[]args)
{
String name;
Scanner s = new Scanner([Link]);

[Link]("Enter your Name: ");


name = [Link]();
[Link]("Hello "+name);
}
}
OUTPUT:

You might also like