Professional Documents
Culture Documents
Galgotias College of Engineering and Technology: Web Technology Lab File
Galgotias College of Engineering and Technology: Web Technology Lab File
Galgotias College of Engineering and Technology: Web Technology Lab File
ENGINEERING AND
TECHNOLOGY
1809710077
CSE-B
Web tech lab
22 – April – 2021
import java.io.BufferedReader;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Scanner;
class Duplicate {
public static void main(String[] args) {
System.out.println("Enter element of array");
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
Hashtable<Integer, Integer> h1 = new Hashtable<>();
for (int i = 0; i < n; i++) {
int t=reader.nextInt();
if(h1.containsKey(t))
{
h1.put(t, h1.get(t)+1);
}
else
{
h1.put(t,1);
}
}
System.out.println("Duplicate elements are : ");
h1.forEach((k,v)->{
if(v>1)
{
System.out.println(k);
}
});
}
}
2) Program to print the elements of an array in reverse order
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Scanner;
class ReverseOrder {
public static void main(String[] args) {
System.out.println("Enter element of array");
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ArrayList<Integer> h1 = new ArrayList<>();
for (int i = 0; i < n; i++) {
int t = reader.nextInt();
h1.add(t);
}
System.out.println("Element in reverse order are : ");
for(int i=h1.size()-1;i>=0;i--)
{
System.out.println(h1.get(i));
}
}
}
3) Program to print the elements of an array present on even position
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Scanner;
class EvenPrint {
public static void main(String[] args) {
System.out.println("Enter element of array");
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ArrayList<Integer> h1 = new ArrayList<>();
for (int i = 0; i < n; i++) {
int t = reader.nextInt();
h1.add(t);
}
System.out.println("Element at even index : ");
for (int i = 0; i < h1.size(); i += 2) {
System.out.println(h1.get(i));
}
}
}
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Scanner;
class LeftRotate {
public static void main(String[] args) {
System.out.println("Enter element of array");
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ArrayList<Integer> h1 = new ArrayList<>();
for (int i = 0; i < n; i++) {
int t = reader.nextInt();
h1.add(t);
}
int f = h1.get(0);
for (int i = 1; i < h1.size(); i++) {
int t = h1.get(i);
h1.set(i - 1, t);
}
h1.set(n - 1, f);
System.out.println("Left rotated : ");
for (int i = 0; i < h1.size(); i += 1) {
System.out.println(h1.get(i));
}
}
}
class Sort {
public static void main(String[] args) {
System.out.println("Enter element of array");
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ArrayList<Integer> h1 = new ArrayList<>();
for (int i = 0; i < n; i++) {
int t = reader.nextInt();
h1.add(t);
}
Collections.sort(h1);
System.out.println("Element sorted : ");
for (int i = 0; i < h1.size(); i++) {
System.out.println(h1.get(i));
}
}
}
class Third {
public static void main(String[] args) {
System.out.println("Enter element of array");
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ArrayList<Integer> h1 = new ArrayList<>();
for (int i = 0; i < n; i++) {
int t = reader.nextInt();
h1.add(t);
}
Collections.sort(h1);
System.out.println("3rd largest element is : ");
System.out.println(h1.get(n - 3));
}
}
Write a program to elaborate the concept of method overloading and constructor overloading.
Method overloading:-
return (x + y);
return (x + y + z);
return (x + y);
// Driver code
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10.5, 20.5));
Constructor overloading:-
class Box
width = w;
height = h;
depth = d;
Box()
double volume()
// Driver code
vol = mybox1.volume();
vol = mybox2.volume();
class Bicycle {
this.gear = gear;
this.speed = speed;
speed -= decrement;
{
speed += increment;
}]
int startHeight)
super(gear, speed);
seatHeight = startHeight;
seatHeight = newValue;
+ seatHeight);
}
// driver class
System.out.println(mb.toString());
class Parent {
void show()
System.out.println("Parent's show()");
@Override
void show()
{
System.out.println("Child's show()");
// Driver class
obj1.show();
obj2.show();
interface IAnimal {
boolean IsDangerous();
boolean IsExtinct();
String GetName();
}
class Cat implements IAnimal {
@Override
public boolean IsExtinct() {
return false;
}
@Override
public String GetName() {
return "Cat";
}
@Override
public boolean IsDangerous() {
return false;
}
}
4) A sandwich is two pieces of bread with something in between. Return the string that is between the first and
last appearance of "bread" in the given string, or return the empty string "" if there are not two pieces of
bread.
getSandwich("breadjambread") → "jam"
getSandwich("xxbreadjambreadyy") → "jam"
getSandwich("xxbreadyy") → ""
import java.io.*;
class GFG
{
try
if (ptr.equals("gfg"))
System.out.print("Same");
else
System.out.print("Not Same");
catch(NullPointerException e)
System.out.print("NullPointerException Caught");
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
char arr[] = { 'g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e',
'k', 's' };
sort(arr);
public class TryCatchExample2 {
public static void main(String[] args) {
try {
int data=50/0;
}
catch(ArithmeticException e)
{ System.out.println(e);
}
System.out.println("rest of the code");
}
}
4). A sandwich is two pieces of bread with something in between. Return the string that is between the
first and last appearance of “bread” in the given string, or return the empty string “” if there are not two
pieces of bread.
getSandwich(“xxbreadyy”)-> “”
import java.util.Scanner;
Lab -4
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Calculator extends Applet implements ActionListener
{
TextField inp;
//Function to add features to the frame
public void init()
{
setBackground(Color.white);
setLayout(null);
int i;
inp = new TextField();
inp.setBounds(150,100,270,50);
this.add(inp);
Button button[] = new Button[10];
for(i=0;i<10;i++)
{
button[i] = new Button(String.valueOf(9-i));
button[i].setBounds(150+((i%3)*50),150+((i/3)*50),50,50);
this.add(button[i]);
button[i].addActionListener(this);
}
Button dec=new Button(".");
dec.setBounds(200,300,50,50);
this.add(dec);
dec.addActionListener(this);
<html>
<head>Cv </head>
<body>
<h3>Vanshika Singh</h3>
<a href = "galgotiascollege.edu">College Info</a><br>
<table border="2px" color = "black" padding = "4px">
<thead>Qualifications</thead>
<tr>
<td> Program </td>
<td> College </td>
<td> Percentage </td>
</tr>
<tr>
<td> B.Tech </td>
<td> Galgotias College of Engineering and Technology </td>
<td> 88 </td>
</tr>
</table>
<h4>Strengths</h4>
<ul>
<li>
Punctuality
</li>
<li>
Hardworking
</li>
<li>
Interest in new technology
</li>
</ul>
<h4>Projects</h4>
<ul>
<li>Sentiment Analysis</li>
<ul>
<li> Description :- Determine the emotion of the user using
there comments</li>
</ul>
</ul>
</body>
</html>