0% found this document useful (0 votes)
2 views32 pages

Java Programming

The document contains a series of HTML and JSP programs that perform various tasks such as finding ASCII values, calculating simple interest, adding digits, checking even/odd status, comparing numbers, and identifying character types. Each program includes a form for user input and displays the results on a new page. The programs demonstrate basic web development skills using Java Server Pages (JSP) and HTML forms.

Uploaded by

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

Java Programming

The document contains a series of HTML and JSP programs that perform various tasks such as finding ASCII values, calculating simple interest, adding digits, checking even/odd status, comparing numbers, and identifying character types. Each program includes a form for user input and displays the results on a new page. The programs demonstrate basic web development skills using Java Server Pages (JSP) and HTML forms.

Uploaded by

easydrawing2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM 1

Write a program to find Asccii Value.

<!DOCTYPE html>

<html>

<head>
<title>ASCII Value Finder</title>

</head>

<body>

<h2>Enter a Character</h2>

<form action="[Link]" method="post">

<input type="text" name="charInput" maxlength="1" required>

<input type="submit" value="Get ASCII Value">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>

<head>

<title>ASCII Result</title>

</head>

<body>

<%

String input = [Link]("charInput");


if (input != null && [Link]() > 0) {

char ch = [Link](0);

int ascii = (int) ch;

%>

<h2>Result</h2>

<p>Character: <%= ch %></p>

<p>ASCII Value: <%= ascii %></p>

<%

} else {

%>

<p>No character entered!</p>

<%

%>

<br>
<a href="[Link]">Go Back</a>

</body>

</html>
OUTPUT:

Character: a
ASCCII Value: 97

PROGRAM 2
Write a program to calculate simple interest.
<!DOCTYPE html>

<html>

<head>

<title>Simple Interest Calculator</title>

</head>

<body>

<h2>Simple Interest Calculator</h2>

<form action="[Link]" method="post">

Principal Amount: <input type="number" name="principal" required><br><br>

Rate of Interest (%): <input type="number" name="rate" required><br><br>

Time (Years): <input type="number" name="time" required><br><br>

<input type="submit" value="Calculate">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>

<title>Simple Interest Result</title>

</head>

<body>

<%

String p = [Link]("principal");

String r = [Link]("rate");
String t = [Link]("time");

if(p != null && r != null && t != null) {

double principal = [Link](p);

double rate = [Link](r);

double time = [Link](t);

double simpleInterest = (principal * rate * time) / 100;

%>

<h2>Result</h2>

<p>Principal Amount: <%= principal %></p>

<p>Rate of Interest: <%= rate %>%</p>

<p>Time: <%= time %> years</p>


<p><b>Simple Interest: <%= simpleInterest %></b></p>

<%

} else {

%>
<p>Please enter all values!</p>
<%

%>

<br>

<a href="[Link]">Go Back</a>

</body>
</html>

OUTPUT:

Principal Amount: 10000.0

Rate of Interest: 5.0%

Time: 2.0 years

Simple Interest: 1000.0

PROGRAM 3
Write a program to add first, middle and last digit.

<!DOCTYPE html>

<html>

<head>

<title>Add First, Middle and Last Digit</title>


</head>
<body>

<h2>Add First, Middle and Last Digit</h2>

<form action="[Link]" method="post">

Enter a Number:

<input type="text" name="number" required>

<br><br>
<input type="submit" value="Calculate">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>

<head>

<title>Result</title>

</head>

<body>
<%

String num = [Link]("number");

if (num != null && [Link]() > 0) {

int length = [Link]();

int first = [Link]([Link](0));


int last = [Link]([Link](length - 1));

int middle = [Link]([Link](length / 2));

int sum = first + middle + last;

%>

<h2>Result</h2>

<p>Number: <%= num %></p>

<p>First Digit: <%= first %></p>

<p>Middle Digit: <%= middle %></p>

<p>Last Digit: <%= last %></p>

<p><b>Sum: <%= sum %></b></p>

<%

} else {
%>

<p>Please enter a valid number!</p>

<%

%>
<br>

<a href="[Link]">Go Back</a>

</body>

</html>

OUTPUT:

Enter a Number: 12345

Number: 12345

First Digit: 1

Middle Digit: 3

Last Digit: 5

Sum: 9

PROGRAM 4
Write a program to find the sum of 2 digits.

<!DOCTYPE html>

<html>

<head>

<title>Sum of Two Digits</title>

</head>

<body>

<h2>Sum of Two Digits</h2>


<form action="[Link]" method="post">

Enter First Number:

<input type="number" name="num1" required>

<br><br>

Enter Second Number:

<input type="number" name="num2" required>


<br><br>

<input type="submit" value="Calculate Sum">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Sum Result</title>
</head>

<body>

<%

String n1 = [Link]("num1");
String n2 = [Link]("num2");
if (n1 != null && n2 != null) {

int num1 = [Link](n1);

int num2 = [Link](n2);

int sum = num1 + num2;

%>

<h2>Result</h2>

<p>First Number: <%= num1 %></p>

<p>Second Number: <%= num2 %></p>

<p><b>Sum: <%= sum %></b></p>

<%

} else {

%>

<p>Please enter both numbers!</p>

<%

%>

<br>
<a href="[Link]">Go Back</a>

</body>

</html>
OUTPUT:

First Number: 10

Second Number: 20

Sum: 30

PROGRAM 5
Write a program to check whether the number is even or odd.

<!DOCTYPE html>

<html>

<head>

<title>Even or Odd Checker</title>

</head>

<body>

<h2>Check Whether a Number is Even or Odd</h2>

<form action="[Link]" method="post">


Enter a Number:
<input type="number" name="num" required>

<br><br>

<input type="submit" value="Check">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Even or Odd Result</title>

</head>

<body>

<%

String n = [Link]("num");

if (n != null && [Link]() > 0) {

int num = [Link](n);


String result;

if (num % 2 == 0) {

result = "Even";

} else {

result = "Odd";

%>

<h2>Result</h2>

<p>Number: <%= num %></p>

<p>Status: <b><%= result %></b></p>

<%

} else {

%>

<p>Please enter a valid number!</p>

<%

%>

<br>

<a href="[Link]">Go Back</a>

</body>

</html>

OUTPUT:

Enter a Number: 15
Status: Odd

PROGRAM 6
Write a program to check number is equal or not if not print
largest

<!DOCTYPE html>

<html>

<head>

<title>Compare Two Numbers</title>

</head>

<body>

<h2>Compare Two Numbers</h2>

<form action="[Link]" method="post">

Enter First Number:

<input type="number" name="num1" required>


<br><br>
Enter Second Number:

<input type="number" name="num2" required>

<br><br>

<input type="submit" value="Compare">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Compare Result</title>

</head>

<body>

<%

String n1 = [Link]("num1");
String n2 = [Link]("num2");

if(n1 != null && n2 != null) {

int num1 = [Link](n1);


int num2 = [Link](n2);
%>

<h2>Result</h2>

<p>First Number: <%= num1 %></p>

<p>Second Number: <%= num2 %></p>

<%

if(num1 == num2) {
%>

<p>The numbers are <b>equal</b>.</p>

<%

} else {

int largest = (num1 > num2) ? num1 : num2;

%>

<p>The numbers are <b>not equal</b>.</p>

<p>The largest number is: <b><%= largest %></b></p>

<%

%>

<br>

<a href="[Link]">Go Back</a>

<%

} else {
%>

<p>Please enter both numbers!</p>

<%

%>
</body>
</html>

OUTPUT:

First Number: 15

Second Number: 20

The numbers are not equal.

The largest number is: 20

PROGRAM 7
Write a program to check buzz number.

<!DOCTYPE html>

<html>

<head>
<title>Buzz Number Checker</title>

</head>

<body>

<h2>Check Buzz Number</h2>

<form action="[Link]" method="post">

Enter a Number:

<input type="number" name="num" required>

<br><br>

<input type="submit" value="Check">

</form>
</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Buzz Number Result</title>

</head>

<body>

<%

String n = [Link]("num");

if (n != null && [Link]() > 0) {

int num = [Link](n);


boolean isBuzz = (num % 7 == 0) || (num % 10 == 7);

%>

<h2>Result</h2>

<p>Number: <%= num %></p>


<%
if (isBuzz) {

%>

<p><b><%= num %> is a Buzz Number.</b></p>

<%

} else {

%>

<p><b><%= num %> is not a Buzz Number.</b></p>

<%
}

%>

<br>

<a href="[Link]">Go Back</a>

<%

} else {

%>

<p>Please enter a valid number!</p>

<%

%>

</body>
</html>

OUTPUT:

Enter the Number: 14


14 is a Buzz Number
PROGRAM 8
Write a program to swap without using third variable.

<!DOCTYPE html>

<html>

<head>

<title>Swap Two Numbers</title>

</head>

<body>

<h2>Swap Two Numbers Without Third Variable</h2>

<form action="[Link]" method="post">

Enter First Number:

<input type="number" name="num1" required>

<br><br>

Enter Second Number:

<input type="number" name="num2" required>

<br><br>

<input type="submit" value="Swap">

</form>
</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Swap Result</title>

</head>

<body>

<%

String n1 = [Link]("num1");

String n2 = [Link]("num2");

if(n1 != null && n2 != null) {

int num1 = [Link](n1);

int num2 = [Link](n2);

// Swapping without third variable

num1 = num1 + num2;

num2 = num1 - num2;

num1 = num1 - num2;


%>
<h2>Result</h2>

<p>After Swapping:</p>

<p>First Number: <%= num1 %></p>

<p>Second Number: <%= num2 %></p>

<%

} else {
%>

<p>Please enter both numbers!</p>

<%

%>

<br>

<a href="[Link]">Go Back</a>

</body>

</html>

OUTPUT:

Before swapping

Enter First Number: 10


Enter Second Number: 20

After swapping

First Number: 20

Second Number: 10
PROGRAM 9
Write a program to check whether character is upper case or
lower case.

<!DOCTYPE html>

<html>

<head>
<title>Uppercase or Lowercase Checker</title>

</head>

<body>

<h2>Check Whether a Character is Uppercase or Lowercase</h2>

<form action="[Link]" method="post">

Enter a Character:

<input type="text" name="charInput" maxlength="1" required>

<br><br>

<input type="submit" value="Check">

</form>

</body>

</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>
<title>Character Case Result</title>

</head>

<body>

<%

String input = [Link]("charInput");

if (input != null && [Link]() > 0) {

char ch = [Link](0);

String result;

if ([Link](ch)) {

result = "Uppercase";

} else if ([Link](ch)) {

result = "Lowercase";
} else {

result = "Not an alphabet character";

%>

<h2>Result</h2>
<p>Character: <%= ch %></p>

<p>Status: <b><%= result %></b></p>

<%

} else {

%>

<p>Please enter a character!</p>

<%
}

%>

<br>

<a href="[Link]">Go Back</a>

</body>

</html>

OUTPUT:

Enter a Character: A

Status: Uppercase
PROGRAM 10
Write a program to check whether the given number is
alphabet, number, or special symbol.

<!DOCTYPE html>
<html>

<head>

<title>Alphabet, Number or Special Symbol Checker</title>

</head>

<body>

<h2>Check Input Type</h2>

<form action="[Link]" method="post">

Enter a Character:

<input type="text" name="inputChar" maxlength="1" required>

<br><br>

<input type="submit" value="Check">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Result</title>

</head>

<body>

<%

String input = [Link]("inputChar");

if (input != null && [Link]() > 0) {

char ch = [Link](0);

String result;

if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {

result = "Alphabet";

else if (ch >= '0' && ch <= '9') {

result = "Number";

}
else {

result = "Special Symbol";

%>

<h2>Result</h2>
<p>Entered Character: <%= ch %></p>

<p>Type: <b><%= result %></b></p>

<%

} else {

%>

<p>Please enter a character!</p>

<%
}

%>

<br>

<a href="[Link]">Go Back</a>

</body>

</html>

OUTPUT:

Enter a Character: A

Entered Character: A

Type: Alphabet
PROGRAM 11
Write a program to check whether the given number is positive,
negative or 0.

<!DOCTYPE html>

<html>

<head>

<title>Positive, Negative or Zero Checker</title>

</head>
<body>

<h2>Check Whether Number is Positive, Negative or Zero</h2>

<form action="[Link]" method="post">

Enter a Number:

<input type="number" name="num" required>

<br><br>

<input type="submit" value="Check">

</form>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<title>Result</title>

</head>

<body>

<%

String n = [Link]("num");

if (n != null && [Link]() > 0) {

int num = [Link](n);

String result;

if (num > 0) {

result = "Positive";

else if (num < 0) {

result = "Negative";

}
else {

result = "Zero";

%>

<h2>Result</h2>
<p>Entered Number: <%= num %></p>

<p>Status: <b><%= result %></b></p>

<%

} else {

%>

<p>Please enter a valid number!</p>

<%
}

%>

<br>

<a href="[Link]">Go Back</a>

</body>

</html>

OUTPUT:

Enter a Number: -5

Entered Number: -5

Status: Negative

You might also like