Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

RandomNumbers

import java.util.*;

public class RandomNum {

public static void main(String[] Args)

Random rd=new Random();

int[] arr= new int[5];

for(int i=0;i<arr.length;i++)

{ arr[i]=rd.nextInt();

for(int i=0;i<arr.length;i++)

{ for(int j =i+1;j<arr.length;j++)

{ if(arr[i]>arr[j])

{ int temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

} } }

for(int i=0; i<arr.length;i++)

{ System.out.println(arr[i]);

} }}
OUTPUT

-2102133063

-984096623

102841630

511041748

2096484836
String Program

public class Count {

public static void main(String[] Args)

{ String line="This website is aw3ome3";

int v=0,c=0,digits=0,spaces=0;

line=line.toLowerCase();

for(int i=0;i<line.length();++i)

{ char ch=line.charAt(i);

if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

{++v;}

else if(ch=='a'||ch<='z')

{++c;}

else if(ch=='0'||ch<='9')

{++digits;}

else if(ch==' ')

{++spaces;} }

System.out.println("vowels:"+v);

System.out.println("Consonents:"+c);

System.out.println("Digits:"+digits);

System.out.println("White Spaces:"+spaces);

System.out.println("length:"+line.length()); }

}
OUTPUT

vowels:7

Consonents:11

Digits:2

White Spaces:3

length:23
Thread

import java.lang.Thread;

class A extends Thread

{ public void run()

{ for(int i=1;i<=5;i++)

{ System.out.println("\t from Thread A=i= "+i);

System.out.println("Exit from A");

}}

class B extends Thread

{ public void run()

{ for(int j=1;j<=5;j++)

System.out.println("\t from Thread B=j= "+j);

System.out.println("Exit from B");

}}

class C extends Thread

{ public void run()

{ for(int k=1;k<=5;k++)

System.out.println("\t from Thread C=k= "+k);

System.out.println("Exit from C");

}}
class ThreadTest

{ public static void main(String[] args)

{ new A().start();

new B().start();

new C().start(); } }

Output:

from Thread A=i= 1

from Thread A=i= 2

from Thread A=i= 3

from Thread A=i= 4

from Thread A=i= 5

Exit from A

from Thread B=j= 1

from Thread B=j= 2

from Thread B=j= 3

from Thread B=j= 4

from Thread B=j= 5

Exit from B

from Thread C=k= 1

from Thread C=k= 2

from Thread C=k= 3

from Thread C=k= 4

from Thread C=k= 5

Exit from C
Exception

import java.lang.Exception;

class myException extends Exception{

myException(String message){

super(message);

}}

public class testmyexception {

public static void main(String[] Args)

{float x=5, y=1000;

try

{float z=( x / y);

if(z<0.01)

{ throw new myException("Number is too small");

}}

catch(myException e)

{System.out.println("Caught my exception");

System.out.println(e.getMessage());}

finally

{System.out.println("I am always here");}

}}

OUTPUT

Caught my exception

Number is too small

I am always here
Applet

import java.awt.*;

import java.applet.*;

public class hellojava extends Applet {

String str;

public void init()

{ str=getParameter("String");

if(str==null)

{ str="Java";

str="Hello"+str;

public void paint(Graphics g)

{ g.drawString(str, 10, 100);

HTML

<html>
<head>
<title>Welcome to apple</title>

</head>
<body>
<applet code= hellojava.class width=400 height=200>
<param name="string" value="Applet">
</applet>
</body>
</html>
OUTPUT
PROGRAM

<html>

<head>

<title>Text format</title></head.

<body>

<h1>About Swami Vivekananda</h1>

<p>His pre_Monastic name is <b> Naren</b></p>

<p>He was born on <strong> 12.01.1863</string></p>

<p>His guru is <b><v>Ramakrishna</v></b></p>

<center><b><i>His famous quotes are:</i></b></center>

<p><b>You are creator of your own destiny </b></p>

<br>

<p><b>Ypou cant belive in god until you believe in yourself </b></p>

<p><b>To be do good </b></p>

<br>

<footer>Swami vivekananda is hero for all the yougster.</footer>

</body>

</html>
OUTPUT
PROGRAM

<html>

<head>

<title>Train time table</title>

</head>

<body bgcolor="pinK"><center>

<h1><u><font color=”green”>

Train schedule </font></u></centre>

<marquee><font color="red"><h5>Passenger are required to have a valid


ID proof for verification</h5>

</font></marquee>

<table align="Center" border="2" width="90%">

<tr>

<th rowspan=5><font color="Yellow">

Welcome to southern railways</font></th>

<th colspan=8><font color="green">Train details in</font></th>

</tr>

<tr>

<th><b>Train No</b></th>

<th><b>Source</b></th>

<th><b>Destination</b></th>

<th><b>Departure</b></th>
<th><b>Arrival</b></th>

</tr>

<tr>

<td>16714</td>

<td>Egmore</td>

<td>Rameshwaram</td>

<td>09:30 PM</td>

<td>11:00 PM</td>

</tr>

<tr>

<td>14023</td>

<td>Central</td>

<td>Madurai</t>

<td>10:00 PM</td>

<td>06:00 AM</td>

</tr>

<tr>

<td>15327</td>

<td>Egmore</td>

<td>Howra</td>

<td>08:30 PM</td>

<td>11:30 AM</td>

</tr>

</table>

</body>
</html>

OUTPUT
PROGRAM

<html>

<head>

<title>Implementing OL&UL list</title>

</head>

<body bg color="pink">

<h1><u>Ordered List</u></h1>

<p>Top Five ODI Batsman</p><br>

<ol type="1">

<li>Virat

<li>Smith

<li>Sharma

<li>Root

<li>Warner

</ol>

<h1><u>Unordered list</u></h1>

<p>Top Five ODI Bowlers</p><br>

<ul type="Disc">

<li>Ashwin

<li>Broad

<li>Boult

<li>Burmhra

<li>Staarc

</ul>
</body></html>

OUTPUT
PROGRAM

<html>

<head>

<title>Exam pk for frames</title>

</head>

<frameset rows="40%,60%">

<frameset cols="50%,50%">

<frame src="Z:\2ex.html">

<frame src="Z:\3ec.html">

</frameset>

<frameset cols="50%,50%">

<frame src="Z:\2ex.html">

<frame src="Z:\3ec.html">

</frameset>

</frameset>

</html>
OUTPUT
PROGRAM

<html>

<head>

<title>Link to another page</title>

</head>

<body>

<a href="Z\2ex.html">

click here </a>

</body>

</html>

<html>

<head>

<title> Department Details</title>

</head>'

<body bg color="green">

<center><h1>Welcome to B.Com(CA)</h1>

</center>

<p><b><u>The department Achievement are: </u> </b>


</p><br>

<p>1. Pper presentation<br>

2. Quiz <br>

3. IQ Test<br>

4. Placements<br></p>

</body>
</html>

OUTPUT
PROGRAMS

<html>

<head>

<title> Image as link</title>

</head>

<body>

<a href="Z:\2ex.html">

<img src="Z:\Desert.jpg">

</a>

</body>

</html>
OUTPUT
PROGRAM

<html>

<head>

<title>mail link</title>

</head>

<body><center><h3>Email link as given below</h3>

<a href="mailto:Some@example.com">send
mail</a></center>

</body></html>

OUPUT
PROGRAM

<html>

<head><title>Working with Span</title>

<style type="text/css">

p{ font size=12pt; font weight:bold; text.align:justify}

.question{ color:brown;font-style:italic}

.answer{color:blue}

.big{font size=16pt; text-decoration:underline; text-transform:upper case;


color:red}

</style></head>

<body>

<p class="question">How to create<span class="big"> Style Sheet</span>


to alter an element?</p>

<p class="answer">If it is implemented with<span class="big"> < Style >


tag</span></p>

<p class="question">what is<span class="big"> CSS?</span></p>

<p class="answer">Cascading Style Sheet</p>

</body>

</html>
OUTPUT
PROGRAM:

<html>

<head><title>Working with WterMarking</title>

<script type="text/javascript">

function bgchange(bg)

document.body.style.background=bg;

</script></head> <body>

<h2><b>Place the cursor on the square box. The background color will
change.</b><h2>

<table width="300" height="100">

<tr>

<td onmouseover="bgchange('red')"
onmouseout="bgchange('transparent')" bgcolor="red"></td>

<td onmouseover="bgchange('blue')"
onmouseout="bgchange('transparent')" bgcolor="blue"></td>

<td onmouseover="bgchange('green')"
onmouseout="bgchange('transparent')" bgcolor="green"></td>

</tr>

</table> </body> </html>


OUTPUT
PROGRAM:

<html>

<head><title>Formatting Text</title>

<style type="text/css">

p.one{color:#00FF00}

p.two{font size:28pt}

h1{font variant:small caps}

h2{font-family:Script}

h3{text.indent:1cm}

h4{text height:500%}

h5{letter spacing:50pt}

h6{text align:center}

p.three{text-decoration:overline}

p.four{text-decoration:line.through}

p.five{direction:rtl}

p.six{background color:yellow}

</style></head>

<body>

<p class="one">Welcome to Text Formatting</p>

<p class="two">All power is in your</p>

<h1>You are the creater</h1>

<h2>Education is the manifestation of power</h2>

<h3>Feel for poor</h3>

<h4>Be a hero</h4>
<h5>Be good</h5>

<h6>Experience is your teacher</h6>

<p class="three">Truth is strength</p>

<p class="four>Dont beleive others</p>

<p class="five">Blessed people are anxious</p>

<p class="six">End of text formatting</p>

</body>

</html>

OUTPUT
PROGRAM:

<html>

<head><title>Array of Elements</title></head>

<body bgcolor="pink">

<script language="javascript">

names=new Array(10);

names[0]="dood";

names[1]="Virat";

names[2]="Rohit";

names[3]="Dhawan";

names[4]="Rahane";

names[5]="Ashwin";

names[6]="Pandya";

names[7]="Ishanth Sharma";

names[8]="Bumrah";

names[9]="Shami";

for(i=0;i<names.length;i++)

{ document.write(names[i]+"<br>") }

</script> </body> </html>


OUTPUT:
PROGRAM:

<html>

<head>

<title>Calculator </title>

<script language="JavaScript" type="text/javascript">

function addition()

a=Number(document.calculator.number1.value);

b=Number(document.calculator.number2.value);

c=a+b;

document.calculator.total.value=c;

</script>

<script language="JavaScript" type="text/javascript">

function subtraction()

a=Number(document.calculator.number1.value);

b=Number(document.calculator.number2.value);

c=a-b;

document.calculator.total.value=c;

</script>

<script language="JavaScript" type="text/javascript">

function multiplication()
{

a=Number(document.calculator.number1.value);

b=Number(document.calculator.number2.value);

c=a*b;

document.calculator.total.value=c;

</script>

<script language="JavaScript" type="text/javascript">

function division()

a=Number(document.calculator.number1.value);

b=Number(document.calculator.number2.value);

c=a/b;

document.calculator.total.value=c;

</script>

<script language="JavaScript" type="text/javascript">

function modulus()

a=Number(document.calculator.number1.value);

b=Number(document.calculator.number2.value);

c=a%b;

document.calculator.total.value=c;

</script>
</head>

<body>

<form name="calculator">

Number 1: <input type="text" name="number1"> <br><br>

Number 2: <input type="text" name="number2"> <br><br>

Result: <input type="text" name="total"> <br><br>

<input type="button" value="ADD" onclick="addition()";>

<input type="button" value="SUB" onclick="subtraction()";>

<input type="button" value="MUL" onclick="multiplication()";>

<input type="button" value="DIV" onclick="division()";>

<input type="button" value="MOD" onclick="modulus()";>

</form>

</body>

</html>

OUTPUT

You might also like