0% found this document useful (0 votes)
23 views9 pages

Ayush Java 5

The document discusses three Java programs - one to create a singly linked list, another to create a singly circular linked list, and another to pass parameters to applets. The first program inserts nodes into a linked list and prints the list. The second program creates a circular linked list by adding nodes and displaying the nodes. The third program reads parameters passed to an applet and displays them.

Uploaded by

Okby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views9 pages

Ayush Java 5

The document discusses three Java programs - one to create a singly linked list, another to create a singly circular linked list, and another to pass parameters to applets. The first program inserts nodes into a linked list and prints the list. The second program creates a circular linked list by adding nodes and displaying the nodes. The third program reads parameters passed to an applet and displays them.

Uploaded by

Okby
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Vidhyadeep insti. Of com. & info.

Technology, anita (kim)

Name :- RAMANI AYUSH

EN No :- E21110403000110108

Sub :- java (Assignment - 5)

Sem :- S.Y B.C.A Sem-4

PAGE NO:-1 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

1) WRITE A PROGRAM TO SINGLY LINKS LIST


import java.io.*;

public class LinkedList {

Node head; // head of list

static class Node {

int data;

Node next;

Node(int d)

data = d;

next = null;

public static LinkedList insert(LinkedList list, int data)

Node new_node = new Node(data);

if (list.head == null) {

list.head = new_node;

else {

Node last = list.head;

while (last.next != null) {

last = last.next;

PAGE NO:-2 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

last.next = new_node;

return list;

public static void printList(LinkedList list)

Node currNode = list.head;

System.out.print("LinkedList: ");

while (currNode != null) {

// Print the data at current node

System.out.print(currNode.data + " ");

currNode = currNode.next;

public static void main(String[] args)

LinkedList list = new LinkedList();

list = insert(list, 1);

list = insert(list, 2);

list = insert(list, 3);

list = insert(list, 4);

list = insert(list, 5);

PAGE NO:-3 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

list = insert(list, 6);

list = insert(list, 7);

list = insert(list, 8);

printList(list);

OUTPUT:-

2) WRITE A PROGRAM TO SINGLY CIRCULAR LIST


public class CreateList {

public class Node{

int data;

Node next;

public Node(int data) {

this.data = data;

public Node head = null;

public Node tail = null;

PAGE NO:-4 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

public void add(int data){

Node newNode = new Node(data);

if(head == null) {

head = newNode;

tail = newNode;

newNode.next = head;

else {

tail.next = newNode;

//New node will become new tail.

tail = newNode;

tail.next = head;

public void display() {

Node current = head;

if(head == null) {

System.out.println("List is empty");

else {

System.out.println("Nodes of the circular linked list: ");

do{

System.out.print(" "+ current.data);

PAGE NO:-5 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

current = current.next;

}while(current != head);

System.out.println();

public static void main(String[] args) {

CreateList cl = new CreateList();

//Adds data to the list

cl.add(1);

cl.add(2);

cl.add(3);

cl.add(4);

//Displays all the nodes present in the list

cl.display();

OUTPUT:-

PAGE NO:-6 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

3) WRITE A PROGRAM TO PASSING PARAMETERS TO APPLETS


import java.awt.*;

import java.applet.*;

public class Applet8 extends Applet

String name;

String age;

String sport;

String food;

String fruit;

String destination;

public void init()

name = getParameter("Name");

age = getParameter("Age");

food = getParameter("Food");

PAGE NO:-7 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

fruit = getParameter("Fruit");

destination = getParameter("Destination");

sport = getParameter("Sport");

public void paint(Graphics g)

g.drawString("Reading parameters passed to this applet -", 20, 20);

g.drawString("Name -" + name, 20, 40);

g.drawString("Age -" + age, 20, 60);

g.drawString("Favorite fruit -" + fruit, 20, 80);

g.drawString("Favorite food -" + food, 20, 100);

g.drawString("Favorite destination -" + name, 20, 120);

g.drawString("Favorite sport -" + sport, 20, 140);

OUTPUT:-

PAGE NO:-8 SUB:-JAVA PREP BY:-RAMANI AYUSH


Vidhyadeep insti. Of com. & info. Technology, anita (kim)

PAGE NO:-9 SUB:-JAVA PREP BY:-RAMANI AYUSH

You might also like