JAVA LAB MANUAL
1) Write a Program to print the text “Welcome to World of Java”.
Public class Welcome
{
public static void main (String args[])
{
[Link] (“welcome to world of Java”);
}
}
Output: - welcome to world of Java
2) To write a Java program to display the values of different data types: int,
char, Boolean, and float.
public class Value {
public static void main(String[] args)
{
int a=10;
char ch='r';
boolean b=true;
float f1=3.14f;
[Link] ("a value="+a);
[Link] ("character value="+ch);
[Link] ("Boolean value="+b);
[Link] ("Float value="+f1);
}
}
Output:-
a value = 10
Character value = r
Boolean value = True
Float value = 3.14f
3) Java program to find area of rectangle
public class Main {
public static void main(String[] args) {
int length = 5;
int width = 2;
int area = length * width;
[Link] ("Area of rectangle: " + area);
}
}
Output:-
Area of rectangle: 10
4) Program to perform arithmetic operations in Java
public class Arith {
public static void main (String[] args) {
int a = 12, b = 5;
[Link] ("a + b = " + (a + b));
[Link] ("a - b = " + (a - b));
[Link] ("a * b = " + (a * b));
[Link] ("a / b = " + (a / b));
[Link] ("a % b = " + (a % b));
}
}
Output:-
a+b = 17
a-b = 7
a*b = 60
a/b = 2
a%b = 2