22MCAL28 - Java Programming Laboratory - Experiments
22MCAL28 - Java Programming Laboratory - Experiments
22MCAL28 - Java Programming Laboratory - Experiments
Program
class Program1 {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
System.out.print(j + " ");
System.out.println();
}
}
}
Output
1
12
123
1234
12345
class Program2 {
public static void main(String[] args) {
int fact = 1, i = 1;
while( i <= 10 )
System.out.println(i + "! = " + (fact = fact * i++));
}
}
Output
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
3.1 To find the area and circumference of the circle by accepting the radius
from the user.
Program
import java.util.Scanner;
Output
3.2 To accept a number and find whether the number is Prime or not
Program
import java.util.Scanner;
Output 1
Output 2
Output 3
Program
Output
Program
class Outer {
private int outdata = 10;
void display() {
Inner in = new Inner();
System.out.println("Accessing from outer class");
System.out.println("The value of outdata is " + outdata);
System.out.println("The value of indata is " + in.indata);
System.out.println();
}
class Inner {
private int indata = 20;
void inmethod() {
System.out.println("Accessing from inner class");
System.out.println("The sum of indata & outdata is " + (outdata + indata));
}
}
}
class Program5 {
public static void main(String args[]) {
Outer out = new Outer();
out.display();
Outer.Inner in = out.new Inner();
in.inmethod();
}
}
Output
Program6(String name)
{
System.out.println("Welcome "+ name);
}
//Method Overloading
public void add(int a, int b)
{
System.out.println("Sum of "+ a +" + "+ b +" = "+ a+b);
}
Output
Welcome
Welcome Yogeesh S
Sum of 5 + 6 = 56
Sum of 5.2 + 6.4 = 11.600000000000001
Output
Circle Drawn
Rectangle Drawn
Program
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
Output