Professional Documents
Culture Documents
Understanding Basic Concepts and Principles of OOP, Using Print Statement in Java Programming Object
Understanding Basic Concepts and Principles of OOP, Using Print Statement in Java Programming Object
LAB # 01
Understanding basic concepts and principles of OOP, using print statement
in Java programming
OBJECT:
Write a program to add two integers and print their sum.
SOURCE CODE:
class Add
{
public static void main (String args[])
{
int a=5,b=10;
System.out.println("Before Addition:-");
System.out.println("Value of a is "+a);
System.out.println("Value of b is "+b);
System.out.println("After Addition:-");
System.out.print("a + b = ");
System.out.print(a+b);
}
}
OUTPUT:
OOP: Lab # 01 2012-CE-303
OBJECT:
Write a program to take inputs from command line and print their sum.
SOURCE CODE:
class TakeInput
{
public static void main (String args[])
{
int n1,n2,n3,sum;
n1=Integer.parseInt(args[0]);
n2=Integer.parseInt(args[1]);
n3=Integer.parseInt(args[2]);
sum=n1+n2+n3;
System.out.println("Sum of inputs is "+sum);
}
}
OUTPUT:
OOP: Lab # 01 2012-CE-303
OBJECT:
Write a program to calculate the voltage by calculating current and resistance and print the
voltage, current and resistance with their units using command line inputs.
SOURCE CODE:
class OhmsLaw
{
public static void main (String args[])
{
int v,i,r;
i=Integer.parseInt(args[0]);
r=Integer.parseInt(args[1]);
v=i*r;
System.out.println("Current (I) = "+i+" Amperes");
System.out.println("Resistance (R) = "+r+" Ohms");
System.out.println("The Voltage (V) = "+v+" Volts");
}
}
OUTPUT: