1a.
public class FR
{
public static int fibonacci(int n)
{
if (n <= 1)
{
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
public static void main(String[] args) {
int n = 10;
[Link]("Fibonacci series of first 10 numbers using recursive(looping) ");
for (int i = 0; i < n; i++)
{
[Link](fibonacci(i) + " ");
}
}
}
1b.
public class FR1
{
public static void fibonacci(int n)
{
int a = 0, b = 1, c;
if (n > 0)
{
[Link](a + " " + b + " ");
for (int i = 2; i < n; i++)
{
c = a + b;
[Link](c + " ");
a = b;
b = c;
}
}
}
public static void main(String[] args)
{
int n = 10;
[Link]("Fibonacci series 10 values using non recursive function(looping)"s;
fibonacci(n);
}
}
2.
import [Link];
public class Mat {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
[Link]("Enter a 2x2 Matrix");
int[][] matrixA = [Link]();
int[][] matrixB = [Link]();
int[][]result = multiplyMatrices(matrixA, matrixB);
[Link]("Result of matrix multiplication:");
for (int i = 0; i < [Link]; i++) {
for (int j = 0; j < result[i].length; j++) {
[Link](result[i][j] + " ");
}
[Link]();
}
}
public static int[][] multiplyMatrices(int[][] matrixA, int[][] matrixB) {
int rowsA = [Link];
int colsA = matrixA[0].length;
int rowsB = [Link];
int colsB = matrixB[0].length;
int[][] result = new int[rowsA][colsB];
for (int i = 0; i < rowsA; i++) {
for (int j = 0; j < colsB; j++) {
result[i][j] = 0;
for (int k = 0; k < colsA; k++) {
result[i][j] += matrixA[i][k] * matrixB[k][j];
}
}
}
return result;
}
}
3.
import [Link];
class Emp
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("enter Employee name:");
String name=[Link]();
[Link]("enter Employee Id:");
int id=[Link]();
[Link]("enter employee age:");
int age=[Link]();
[Link]("enter employee salary:");
int sal=[Link]();
[Link]("Employee DetailS");
[Link]("Name is :%s\n",name);
[Link]("ID is :"+id);
[Link]("age is :"+age);
[Link]("Sal is :"+sal);
}
}
4a.
package Mypackage;
public class Student
{
String name;
String usn;
int sub1;
int sub2;
int sub3;
int marks;
double per;
public Student(String name,String usn,int sub1,int sub2,int sub3)
{
[Link]=name;
[Link]=usn;
this.sub1=sub1;
this.sub2=sub2;
this.sub3=sub3;
}
public void display()
{
[Link]("Name :"+name);
[Link]("usn :"+usn);
[Link]("Marks of 3 subjects are: " + sub1 + " " + sub2 + " " + sub3);
int marks=sub1+sub2+sub3;
double per=marks/3;
[Link]("marks is "+marks);
[Link]("Percentage is "+per);
}
}
4b.
import [Link];
class Main
{
public static void main(String args[])
{
Student obj=new Student("manoj","ENG23MCA018",60,70,80);
[Link]();
}
}
5.
import [Link].*;
import [Link].*;
/*<applet code="FirstApplet" width=500 height=300></applet>*/
public class FirstApplet extends Applet
{
public void paint(Graphics g)
{
[Link]([Link]);
Font font=new Font("Arial",[Link],16);
[Link](font);
[Link]("This is My First applet",60,110);
}
}
6a.
import [Link].*;
import [Link].*;
/*<applet code="Fact" width=500 height=300></applet>*/
public class Fact extends Applet
{
static int n = 6;
public void paint(Graphics g)
{
int F = 1;
for(int i = 1; i <= n; i++)
{
F *= i;
}
[Link]([Link]);
Font font = new Font("Arial", [Link], 16);
[Link](font);
[Link]("Factorial of " + n + " is: " + F, 60, 110);
}
}
6b.
import [Link].*;
import [Link].*;
/*<applet code="Parameter" height="300" width="500">
<param name="PGM" value="Student details using parameter passing in applets" />
<param name="name" value="Manoj k h" />
<param name="age" value="22" />
<param name="USN" value="ENG23MCA018" />
<param name="Course" value="MCA" />
</applet> */
public class Parameter extends Applet
{
String a;
String b;
String c;
String d;
String e;
public void init()
{
a=getParameter("PGM");
b=getParameter("name");
c=getParameter("age");
d=getParameter("USN");
e=getParameter("course");
}
public void paint(Graphics g)
{
[Link]([Link]);
Font font = new Font("Arial", [Link], 20);
[Link](font);[Link](a, 20,20);
[Link]("Name: " + b,20,40);
[Link]("Age: " + c, 20, 60);
[Link]("USN : " + d, 20, 80);
[Link]("Course: " + e, 20, 100);
7.
import [Link].*;
import [Link].*;
import [Link].*;
public class MouseEventDemo extends JFrame implements MouseListener,
MouseMotionListener
{
JLabel label;
public MouseEventDemo()
{
setTitle("Mouse Event Demo");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label = new JLabel();
[Link](20, 50, 200, 20);
addMouseListener(this);
addMouseMotionListener(this);
add(label);
setLayout(null);
setVisible(true);
}
public void mouseClicked(MouseEvent e)
{
[Link]("Mouse Clicked at: (" + [Link]() + ", " + [Link]() + ")");
}
public void mousePressed(MouseEvent e)
{
[Link]("Mouse Pressed at: (" + [Link]() + ", " + [Link]() + ")");
}
public void mouseReleased(MouseEvent e)
{
[Link]("Mouse Released at: (" + [Link]() + ", " + [Link]() + ")");
}
public void mouseEntered(MouseEvent e)
{
[Link]("Mouse Entered the Frame");
}
public void mouseExited(MouseEvent e)
{
[Link]("Mouse Exited the Frame");
}
public void mouseDragged(MouseEvent e)
{
[Link]("Mouse Dragged at: (" + [Link]() + ", " + [Link]() + ")");
}
public void mouseMoved(MouseEvent e)
{
[Link]("Mouse Moved at: (" + [Link]() + ", " + [Link]() + ")");
}
public static void main(String[] args)
{
new MouseEventDemo();
}
}
8.
import [Link].*;
import [Link].*;
public class KeyEventDemo extends JFrame implements KeyListener {
JLabel label;
public SimpleKeyEventDemo() {
setTitle("Simple Key Event Demo");
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
label = new JLabel("Type something", [Link]);
[Link](50, 100, 200, 50);
addKeyListener(this);
add(label);
setLayout(null);
setVisible(true);
setFocusable(true); // Ensures the frame can capture key events
}
public void keyPressed(KeyEvent e) {
[Link]("Key Pressed: " + [Link]());
}
public void keyReleased(KeyEvent e) {
[Link]("Key Released: " + [Link]());
}
public void keyTyped(KeyEvent e) {
[Link]("Key Typed: " + [Link]());
}
public static void main(String[] args) {
new SimpleKeyEventDemo();
}
}
9.
import [Link].*;
import [Link].*;
public class Pmg_connect
{
public static void main(String[] args)
{
String url = "jdbc:mysql://localhost:3306/Pmg_connect?useSSL=false";
String username = "root";
String password = "Manojkh#2002";
try
{
Connection con = [Link](url, username, password);
[Link]("Connected to MySQL database successfully!");
[Link]();
}
catch (SQLException e)
{
[Link]();
}
}
}
10.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class JDBC {
public static void main(String[] args) {
String jdbcURL = "jdbc:mysql://localhost:3306/Pmg_connect";
String username = "root";
String password = "Manojkh#2002";
try (
Connection connection = [Link](jdbcURL, username, password);
Statement statement = [Link]()) {
[Link]("CREATE TABLE IF NOT EXISTS employees (ID INT AUTO_INCREMENT,
Name VARCHAR(100), PRIMARY KEY (ID))");
[Link]("INSERT INTO employees (Name) VALUES ('John Doe'), ('Jane Doe')");
ResultSet resultSet = [Link]("SELECT * FROM Users");
while ([Link]()) {
[Link]("ID: " + [Link]("ID") + ", Name: " +
[Link]("Name"));
}
} catch (SQLException e) {
[Link]();
}
}
}