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

Java Week 1 Lab Programs

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)
40 views7 pages

Java Week 1 Lab Programs

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
You are on page 1/ 7

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();
lo.first=20;
lo.second = 10;
System.out.println(lo.first+lo.second);
}
}
OUTPUT:

2. // Dynamic Addition of two Numbers

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

3. // Dynamic Multiplication

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

4. // Dynamic Division

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

5. // Dynamic Name Display


import java.util.Scanner;
public class LabOne5
{
public static void main(String[]args)
{
String name;
Scanner s = new Scanner(System.in);

System.out.println("Enter your Name: ");


name = s.nextLine();
System.out.println("Hello "+name);
}
}
OUTPUT:

You might also like