THADOMAL SHAHANI ENGINEERING
COLLEGE
DEPARTMENT OF INFORMATION TECHNOLOGY
Roll no:S13-58
[Link] OF JAVA
Aim 1.1: Program to find square and cube of a given number
Theory:
The program calculates the square and cube of a number entered by the user. It uses basic
multiplication to find the square (number × number) and cube (number × number × number).
The results are then displayed to the user.
Program :
import [Link].*;
class SquareCube {
public static void main(String h[])
{ Scanner sc = new Scanner([Link]);
[Link]("Enter a number:");
int num = [Link]();
[Link]("The square = " + (num * num));
[Link]("The cube = " + (num * num * num));
Output:
Conclusion:
This program helps understand how to perform simple mathematical operations like squaring and
cubing. It also shows how to work with numerical input and generate correct output. It's a basic
yet important step in learning logic building.
Aim 1.2: Program to find area and circumference of a circle
Theory:
The program calculates the area and circumference of a circle using the given radius. The
formulas used are: Area = π × r² and Circumference = 2 × π × r. The value of π is typically taken
as 3.14 for more precision
Program :
import [Link].*;
class AreaCirc {
public static void main(String h[])
{ Scanner sc = new Scanner([Link]);
[Link]("Enter the radius:");
int radius = [Link]();
double area = 3.14 * radius * radius;
double circ = 2 * 3.14 * radius;
[Link]("The area of the circle = " + area);
[Link]("The circumference of circle = " + circ);
Output:
Conclusion:
This program shows how to apply standard formulas to solve geometry-based problems. It
strengthens the understanding of mathematical operations and formula implementation in
programming. It’s useful for solving real-world problems involving circular shapes.
Aim 1.3: Program to check if character is a vowel
Theory:
The program checks whether the entered character is a vowel by comparing it against the five
vowels: a, e, i, o, u (both in lowercase and uppercase). A simple if-else is used to determine and
display the result.
Program :
import [Link].*;
class Vowel {
public static void main(String h[])
{ Scanner sc = new Scanner([Link]);
[Link]("Enter a
character:"); char c =
[Link]().charAt(0);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c ==
'U') [Link]("The character is a
vowel");
else
[Link]("The character is not a vowel");
Output:
Conclusion:
This program helps in understanding character comparison and decision-making using
conditional statements. It builds logic for identifying specific patterns in user input. Such
concepts are useful in string processing and validation tasks.
Aim 1.4: Program to find greatest of three numbers
Theory:
The program compares three numbers to find the greatest among them. It uses conditional
statements like if-else to check which number is larger than the others. The logic is based on
simple comparisons between the three values.
Program :
import [Link].*;
class Greatest {
public static void main(String h[])
{ Scanner sc = new Scanner([Link]);
[Link]("Enter three numbers:");
int n1 = [Link]();
int n2 = [Link]();
int n3 = [Link]();
int great = 0;
if (n1 >= n2 && n1 >= n3)
great = n1;
if (n2 >= n1 && n2 >= n3)
great = n2;
if (n3 >= n1 && n3 >= n2)
great = n3;
[Link]("The greatest number is: " + great);
Output:
Conclusion:
This program builds understanding of logical comparisons and decision-making in programming.
It is helpful for solving problems that involve evaluating multiple
Aim 1.5: Program to check if a number is a two digit number
Theory:
The program checks whether a given number lies between 10 and 99 to determine if it's a two-
digit number. It uses conditional statements to verify this numerical range and then prints the
result.
Program :
import [Link].*;
class TwoDigit {
public static void main(String h[])
{ Scanner sc = new Scanner([Link]);
[Link]("Enter a number:");
int num = [Link]();
if (num >= 10 && num < 100)
[Link]("The number " + num + " is a two digit number");
else
[Link]("The number " + num + " is not a two digit number");
Output:
Conclusion:
This program strengthens understanding of number ranges and logical conditions. It is useful for
validating input types based on digit count. Such checks are commonly used in form validations
and basic data filtering.
Aim 1.6: . Program to calculate Power of a number
Theory:
The program calculates the power of a number using the formula: base^exponent. It multiplies
the base by itself for the number of times specified by the exponent, for efficiency and
simplicity.
Program:
import [Link].*;
class Power {
public static void main(String[] args)
{ Scanner sc = new Scanner([Link]);
[Link]("Enter the base number:");
int N = [Link]();
[Link]("Enter the power:");
int P = [Link]();
int pow = 1;
for (int i = 1; i <= P; i++)
pow *= N;
[Link]("Result = " + pow);
Output:
Conclusion:
This program helps in understanding repeated multiplication and how to implement
exponentiation. It is commonly used in mathematical applications and scientific computations. It
builds a strong base for more complex operations involving powers and roots