0% found this document useful (0 votes)
3 views50 pages

Computer Project

The document contains multiple Java programs that demonstrate various functionalities such as displaying a bot, calculating sums, products, areas, and handling user input for mathematical operations. Each program is accompanied by variable descriptions detailing the data types and purposes of the variables used. The programs cover a range of topics, including arithmetic operations, geometry, and conditional statements.

Uploaded by

i48597669
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)
3 views50 pages

Computer Project

The document contains multiple Java programs that demonstrate various functionalities such as displaying a bot, calculating sums, products, areas, and handling user input for mathematical operations. Each program is accompanied by variable descriptions detailing the data types and purposes of the variables used. The programs cover a range of topics, including arithmetic operations, geometry, and conditional statements.

Uploaded by

i48597669
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

Program 1

//Program to display a Bot


public class Main
{
public static void main(String[] args)
{
[Link](" * * * * *");
[Link](" * o o *");
[Link](" * ^ *");
[Link](" * V *");
[Link](" * * * * *");
[Link]("* * * * * *");
[Link](" * *");
[Link](" * *");
[Link](" * *");
[Link](" * * * * *");
[Link](" * * * *");
}
}

Output:
Program 2
//Program to display a Bill
public class Bill
{
public static void main(String args[])
{
[Link](" ");
[Link](" @@@@@@@@@@@@@@@@@");
[Link](" @ ABC Juice House @");
[Link](" @@@@@@@@@@@@@@@@@");
[Link](" ");
[Link](" ");
[Link](" ");
[Link]("[Link] Item Quantity Rate");
[Link](" 1 Mango Juice 2 \u20B9100.00");
[Link](" 2 Grape Juice 1 \u20B940.00");
[Link](" 3 Fig Juice 3 \u20B9300.00");
[Link](" 4 Orange Juice 1 \u20B960.00");
[Link]("-----------------------------------------------------");
[Link](" Total \u20B9500.00");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" Thank you !!! Visit again !!!");

}
}

Output:
Program 3
//Program to display the sum and product of two numbers
public class SumPro
{
public static void main(String args[])
{
int x = 45, y = 62;
int s = x + y;
int p = x * y;
[Link]("The value of x is "+x);
[Link]("The value of Y is "+y);
[Link]("");
[Link]("");
[Link]("Sum of x and y is "+s);
[Link]("");
[Link]("Product of x and y is "+p);
}
}

Output:

Variable Description :

Variable Data Type Description

x int To store the value of a number

y int To store the value of a number

s int To store the sum of 2 numbers

p int To store the product of 2 numbers


Program 4
//Program to display the quotient and remainder of two numbers
public class Division
{
public static void main(String args[])
{
int p = 55 , q = 20 ;
int d= p / q ;
int r = p % q ;
[Link]("The value of p is "+p);
[Link]("The value of q is "+q);
[Link]("");
[Link]("");
[Link]("Quotient of p and q is "+d);
[Link]("");
[Link]("Remainder of p and q is "+r);
}
}

Output:

Variable Description :

Variable Data Type Description

p int To store the value of a number

q int To store the value of a number

q int To store the quotient of 2 numbers

r int To store the remainder of 2 numbers


Program 5
//Program to display the sum, difference and product
public class Program6
{
public static void main(String args[])
{
double a=12.35, b=7.3;
double s=a+b;
double d=a-b;
double p=a*b;
[Link]("Sum is "+s);
[Link]("Difference is "+d);
[Link]("Product is "+p);
}
}

Output:

Variable Description :

Variable Data Type Description

a double To store the value of a number

b double To store the value of a number

s double To store the sum of 2 numbers

d double To store the difference of 2 numbers

p double To store the product of 2 numbers

//Program to display the area and perimeter of the square


Program 6
public class Program7
{
public static void main(String args[])
{
double s=12.5;
double a=s*s;
double p=4*s;
[Link]("Side of the square is "+s+" cm");
[Link]("");
[Link]("Area of a square= " +a+" squared cm");
[Link]("");
[Link]("Perimeter of a square= "+p+"cm");
}
}

Output:

Variable Description :

Variable Data Type Description

s double To store the value of the side

a double To to store value of area

p double To store value of perimeter

//To display information of the student


public class Program8
Program 7
{
public static void main (String args[])
{
String n = "Gideon";
int sc = 12;
int rn = 25;
String s = "Computer Application";
String sn = "Stanes School";
[Link]("Name: " + n);
[Link]("Class: " + sc);
[Link]("Roll No: " + rn);
[Link]("Subject: " + s);
[Link]("School: " + sn);
}
}

Output:

Variable Description :

Variable Data Type Description

n String To store student name

sc int To store student class

rn int To store student’s roll no.

s String To store subject

sn String To store string name

//To find the average of three numbers


public class Program10
Program 8
{
public static void main(String args [])
{
int n1 = 47;
int n2 = 39;
int n3 = 99;
double a = (n1 + n2 + n3) / 3.0;
[Link]("The average of the three numbers is: " + a);
}
}

Output:

Variable Description :

Variable Data Type Description

n1 int To store the value of first number

n2 int To store the value of second number

n3 int To store the value of third number

a double To store the value of average

//To find the area and perimeter of a circle


public class Prgm12
Program 9
{
public static void main(String args[])
{
double r = 5.0;
double a = (22.0/7.0) * r * r;
double p = 2.0 * (22.0/7.0) * r;
[Link]("Radius of the circle: " + r);
[Link]("Area of the circle: " + a);
[Link]("Perimeter of the circle: " + p);
}
}

Output:

Variable Description :

Variable Data Type Description

r double To store the value of radius

a double To store value of area

p double To store value of perimeter

// To convert Celsius to Fahrenheit


public class Prgm0
{
public static void main(String args[])
Program 10
{
double c = 74.0;
double f = (c * 9.0 / 5.0) + 32.0;
[Link]("Temperature in Fahrenheit: " + f);
}
}

Output:

Variable Description :

Variable Data Type Description

c double To store value in Celsius

f double To store value in fahrenheit

//To input three number and find the greatest and smallest number
import [Link].*;
public class Page145_Q1
{
Program 11
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter three numbers: ");
int n1 = [Link]();
int n2 = [Link]();
int n3 = [Link]();
int g = [Link](n1, [Link](n2, n3));
int s = [Link](n1, [Link](n2, n3));
[Link]("Greatest number: " + g);
[Link]("Smallest number: " + s);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n1 int To store the value of first number

n2 int To store the value of second number

n3 int To store the value of third number

g int To store the value of greatest number

s int To store the value of smallest number

//To calculate and display the hypotenuse of a Right Triangle by taking perpendicular and base as
inputs using the formula h= √p² +b²
import [Link].*;
public class Page145_Q2
{
Program 12
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter the perpendicular and base of the triangle: ");
double p = [Link]();
double b = [Link]();
double h = [Link]((([Link](p,2)) + ([Link](b,2))));
[Link]("The hypotenuse of the triangle is: " + h);
}
}

Output:

Variable Description :

Variable Data type Description

sc Scanner Scanner variable

p double To store the value of perpendicular

b double To store the value of base

h double To store the value of hypotenuse

//Write a program in Java to calculate the average mark obtained and finally display the marks
in rounded off form. Take Physics, Chemistry and Biology Marks as inputs.
import [Link].*;
public class Page145_Q4
{
public static void main(String args[])
Program 13
{
Scanner sc = new Scanner([Link]);
[Link]("Enter marks for Physics, Chemistry and Biology: ");
double p = [Link]();
double c = [Link]();
double b = [Link]();
double a = (p + c + b) / 3;
double r = [Link](a);
[Link]("The rounded off average marks are: " + r);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

p double To store Physics marks

c double To store Chemistry marks

b double To store Biology marks

a double To store average of the


three

r double To store rounded off


value

//To accept the length of the pendulum and gravity g from the user. Calculate and display the time period using the formula T= 2π
√(1/g)
import [Link].*;
public class Prgm16
{
public static void main (String args[])
{
Program 14
Scanner sc = new Scanner([Link]);
double l, g, t =0.0;
[Link]("Enter the length of the pendulum and gravity: ");
l = [Link]();
g = [Link]();
t = 2 * [Link] * [Link](1/g);
[Link]("Time Period: "+t);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

l double To store length of the pendulum

g double To store gravity

t double To store time period

//Calculate and display the value of the following expression ∛(x^y + z^x) / √((y+10)^x)
import [Link].*;
public class Prgm17
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter the value of x, y and z: ");
Program 15
double x= [Link]();
double y= [Link]();
double z= [Link]();
double a= [Link]([Link](x, y) + [Link](z, x)) /[Link]([Link](y + 10, x));
[Link]("The result of the expression is: " +a);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

x double To store the value first number

y double To store the value of second number

z double To store the value of third number

a double To store the result of the expression

//Find the Absolute value of a number


import [Link].*;
public class MathAbs
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
double n = [Link]();
Program 16
double a = [Link](n);
[Link]("Absolute value of " + n + " = " + a);
}
}

Output:

Variable Description :

Variable Data type Description

sc Scanner Scanner variable

n double To store the value of the number

a double To store the absolute value

// To find the floor and ceil value of a number


import [Link].*;
public class CeilFloor
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter a decimal number: ");
double n= [Link]();
Program 17
double c= [Link] (n);
double f= [Link] (n);
[Link]("Ceiling value: " +c);
[Link]("Floor value: " +f);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable


n double To store the value of the input number

c double To store ceil value

f double To store floor value

// To find the square of a number


import [Link].*;
public class MathPow
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
double n = [Link]();
Program 18
double s = [Link](n, 2);
[Link]("Square of " + n + " = " + s);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n double To store the input number

s double To store the square number

//To find nearest integer of a decimal number


import [Link].*;
public class MathRint
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter a decimal number: ");
double n = [Link]();
Program 19
double i = [Link](n);
[Link]("Nearest integer to " + n + " = " +i);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n double To store the input number

i double To store the rint value

//To print random number between 0 and 1


public class MathRandom
{
public static void main(String args[])
{
double r = [Link]();
[Link]("Random decimal number between 0 and 1: " + r);
}
}
Program 20

Output:

Variable Description :

Variable Data Type Description

r double To store the random value

//To check if a number is positive, negative or zero


import [Link].*;
public class CondStmt1
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter a number:");
int n = [Link]();
if (n>0)
Program 21
{
[Link]("The number is positive.");
}
else if (n<0)
{
[Link]("The number is negative.");
}
else
{
[Link]("The number is zero.");
}

}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number

//To check if a number is even or odd


import [Link].*;
public class CondStmt2
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter a number:");
int n = [Link]();
if (n % 2 == 0)
{
Program 22
[Link]("The number is even.");
}
else
{
[Link]("The number is odd.");
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number

//To find the largest of three numbers


import [Link].*;
public class CondStmt3
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter three numbers:");
int a = [Link]();
int b = [Link]();
int c = [Link]();
if (a > b && a > c)
Program 23
{
[Link]("The largest number is: " + a);
}
else if (b > c)
{
[Link]("The largest number is: " + b);
}
else
{
[Link]("The largest number is: " + c);
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

a int To input the value of first number

b int To store the value of second number

c int To store the value of third number

//To check if number is perfect square or not


import [Link].*;
public class CondStmt4
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter a number to check if it is a perfect square:");
int n = [Link]();
int s = (int) [Link](n);
if (s * s == n)
{
Program 24
[Link]("The number is a perfect square.");
}
else
{
[Link]("The number is not a perfect square.");
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store input number

s int To store square root of the input number

//To calculate grade based on marks


import [Link].*;
public class CondStmt5
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter marks out of 100:");
int m = [Link]();
if (m >= 90)
{
[Link]("Grade: A");
Program 25
}
else if (m >= 75)
{
[Link]("Grade: B");
}
else if (m >= 50)
{
[Link]("Grade: C");
}
else
{
[Link]("Grade: F");
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

m int To input

//To print number in words


import [Link].*;
public class SwitchCase1
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter a number from 1 to 9:");
int n = [Link]();
switch (n)
{
case 1:
Program 26
[Link]("One");
break;
case 2:
[Link]("Two");
break;
case 3:
[Link]("Three");
break;
case 4:
[Link]("Four");
break;
case 5:
[Link]("Five");
break;
case 6:
[Link]("Six");
break;
case 7:
[Link]("Seven");
break;
case 8:
[Link]("Eight");
break;
case 9:
[Link]("Nine");
break;
default:
[Link]("Invalid number.");
}
}
}
Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable


n int To store the input number

//To print the day of the week


import [Link].*;
public class SwitchCase2
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter a number from 1 to 7 for the day of the week:");
int d = [Link]();
switch (d)
{
case 1:
Program 27
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
case 3:
[Link]("Wednesday");
break;
case 4:
[Link]("Thursday");
break;
case 5:
[Link]("Friday");
break;
case 6:
[Link]("Saturday");
break;
case 7:
[Link]("Sunday");
break;
default:
[Link]("Invalid day number.");
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

d int To store the input number for finding the day


//To check for vowel or consonant
import [Link].*;
public class SwitchCase3
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter a character in lower case:");
char ch = [Link]().charAt(0);
switch (ch)
{
case 'a':
Program 28
case 'e':
case 'i':
case 'o':
case 'u':
[Link]("The character is a vowel.");
break;
default:
if (ch >= 'a' && ch <= 'z')
{
[Link]("The character is a consonant.");
}
else
{
[Link]("Invalid input");
}
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

ch char To store the input character (alphabet)

//To check season


import [Link].*;
public class SwitchCase4
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Enter a month number:");
int n = [Link]();
switch (n)
{
case 1:
case 2:
Program 29
case 12:
[Link]("Winter");
break;
case 3:
case 4:
case 5:
[Link]("Summer");
break;
case 6:
case 7:
case 8:
case 9:
[Link]("Monsoon");
break;
case 10:
case 11:
[Link]("Autumn");
break;
default:
[Link]("Invalid month number");
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number


//To convert units
import [Link].*;
public class SwitchCase5
{
public static void main(String args[])
{
Scanner sc= new Scanner ([Link]);
[Link]("Choose a conversion option: \n1. Kilometers to Miles\n2. Celsius to Fahrenheit\n3.
Kilograms to Pounds\n4. Meters to Feet");
int n = [Link]();
switch (n)
{
case 1:
[Link]("Enter kilometers:");
double k= [Link]();
Program 30
[Link]("Miles: " +(k * 0.621371));
break;
case 2:
[Link]("Enter Celsius:");
double c= [Link]();
[Link]("Fahrenheit: " +((c * 9/5) + 32));
break;
case 3:
[Link]("Enter kilograms:");
double kg= [Link]();
[Link]("Pounds: " +(kg * 2.20462));
break;
case 4:
[Link]("Enter meters:");
double m= [Link]();
[Link]("Feet: " +(m * 3.28084));
break;
default:
[Link]("Invalid option");
}
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number (choice)

k double To store the input Kilometers

c double To store the input Celsius

kg double To store the input Kilograms

m double To store the input Meters


//To display a message on the screen
import [Link].*;
public class Page184_Prog1
{
public static void main(String args[])
{
for ( int a= 1; a<= 5; a++)
[Link]("Happy New year!!!");
}
}

Output :
Program 31

Variable Description :

Variable Data Type Description

a int Loop variable

//To display all natural numbers from 1 to 10


public class Page187_Prog2
{
public static void main(String args[])
{
[Link]("Natural Numbers from 1 to 20");
for ( int i= 1; i<= 10; i++)
[Link](i);
}
}

Output:
Program 32

Variable Description :

Variable Data Type Description

i int Loop variable

//To input 10 different numbers and display the sum of odd numbers only using for loop
import [Link].*;
public class Page188_Prog3
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
int i, n, s=0;
for (i= 1; i<= 10; i++)
{
[Link]("Enter 10 different numbers one by one:");
n= [Link]();
if (n%2!=0)
s= s+n;
}
Program 33
[Link]("Sum of odd numbers= "+s);
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

i int Loop variable

n int To store the input number

s int To store the sum of the odd numbers

//To input the number of digits and find squares till that number
import [Link].*;
public class ForLoop4
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("Enter the number of terms: ");
int n = [Link]();
[Link]("The squares of the first " + n + " numbers are:");
for (int i = 1; i <= n; i++)
{
[Link]((i * i) + " ");
}
}
Program 34
}

Output :

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

i int Loop variable

n int To store the input number of terms

//To display multiplication tables


import [Link].*;
public class ForLoop5
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("Enter a number:");
int n= [Link]();
for (int i = 1; i <= 10; i++)
{
[Link](n+ " x " + i + " = " + (n* i));
}
}
}
Program 35

Output :

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

i int Loop variable

n int To store the input number

//To find the factorial of a number


import [Link].*;
public class ForLoop6
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("Enter a number:");
int n= [Link]();
int f= 1;
for (int i = 1; i <= n; i++)
{
f= f*i;
}
[Link]("Factorial of " +n+ " is " +f);
Program 36
}
}

Output :

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

i int Loop variable

n int To store the input number

f int To store the factorial of a number

//To find the sum of digits of a number


import [Link].*;
public class WhileLoop7
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("Enter a number:");
int n = [Link]();
int s = 0;
while (n > 0)
{
s += n % 10;
n /= 10;
}
[Link]("Sum of digits = "+s);
Program 37
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number

s int To store the sum of digits of m

//To display the reversed number


import [Link].*;
public class WhileLoop8
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("Enter a number:");
int n = [Link]();
int r = 0;
while (n > 0)
{
r = r * 10 + n % 10;
n /= 10;
}
[Link]("Reversed number = " + r);
}
Program 38
}

Output :

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number

r int To store the reversed number of the input number

//To find the sum of even numbers till n


import [Link].*;
public class ForLoop9
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("Enter the value of n:");
int n = [Link]();
int s = 0;
for (int i = 2; i <= n; i += 2)
{
s += i;
}
[Link]("Sum of even numbers from 1 to " + n + " is " + s);
}
}
Program 39

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

i int Loop variable

n int To store the input number of terms

s int To store the sum of even numbers till n

//To print the first n odd numbers


import [Link].*;
public class ForLoop10
{
public static void main(String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("Enter the value of n:");
int n = [Link]();
for (int i = 1; i <= n; i++)
{
[Link]((2 * i - 1) + " ");
}
}
}
Program 40
Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

i int Loop variable

n int To store the input number

//To input a number and check if it is spy number


import [Link].*;
public class Spy1
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int n, s = 0, p = 1, d;
[Link]("Enter a number: ");
n = [Link]();
int temp = n;
while (n > 0)
{
d = n % 10;
s += d;
p *= d;
n /= 10;
Program 41
}
if (s == p)
[Link](temp + " is a Spy number.");
else
[Link](temp + " is not a Spy number.");
}
}

Output:

Variable Description :

Variable Data Type Description


sc Scanner Scanner variable

n int To store the input number

s int To store the sum of digits

p int To store the product of digits

d int To store the each digit of the number

temp int To store the original value of of n

//To input a number and check if it is niven number


import [Link].*;
public class Niven2
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int n, s = 0, d;
[Link]("Enter a number: ");
n = [Link]();
int temp = n;
while (n > 0)
{
d = n % 10;
s += d;
n /= 10;
}
Program 42
if (temp % s == 0)
[Link](temp + " is a Niven number.");
else
[Link](temp + " is not a Niven number.");
}
}

Output :

Variable Description :

Variable Data Type Description


sc Scanner Scanner variable

n int To store the input number

s int To store the sum of the digits of the number

d int To store each digit if the number

temp int To store the original value of n

//To input a number and check if it is neon number


import [Link].*;
public class Neon3
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int n, s= 0, d;
[Link]("Enter a number: ");
n= [Link]();
int sq= n * n;
while (sq> 0)
{
d= sq % 10;
s += d;
sq/= 10;
}
if (s== n)
Program 43
[Link](n+ " is a Neon number.");
else
[Link](n+ " is not a Neon number.");
}
}

Output:

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number

s int To store the sum of the digits

d int To store each digit of the number

sq int To store the square of the number

//To input a number and check if it is armstrong number


import [Link].*;
public class Armstrong4
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int n, s= 0, d, c= 0, temp;

[Link]("Enter a number: ");


n = [Link]();
temp= n;
while (temp > 0)
{
temp /= 10;
c++;
}
temp = n;
while (temp > 0)
Program 44
{
d= temp % 10;
s+= [Link] (d, c);
temp/= 10;
}
if (s== n)
[Link](n+" is an Armstrong number.");
else
[Link](n+" is not an Armstrong number.");
}
}

Output :

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number

s int To store the sum of the digits

d int To store each digit of the number

c int To store the number of digits

temp int To store the original number

//To input a number and check if it is Palindrome number


import [Link].*;
public class Palindrome5
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int n, r= 0, d, o;
[Link]("Enter a number: ");
n = [Link]();
o = n;
while (n > 0) {
d = n % 10;
r = r * 10 + d;
n/= 10;
}
if (o== r)
[Link](o+" is a Palindrome number.");
else
Program 45
[Link](o+" is not a Palindrome number.");
}
}

Output :

Variable Description :

Variable Data Type Description

sc Scanner Scanner variable

n int To store the input number

r int To store the reversed number

d int To store each digit of the number

o int To store the original number

//To print square


public class SquarePattern1
{
public static void main(String args[])
{
for (int i=1; i<5; i++)
{
for (int j=1; j<=5; j++)
{
[Link]("! ");
}
[Link]();
}
}
}

Output :
Program 46

Variable Description :

Variable Data Type Description

i int Outer Loop variable

j int Inner Loop variable

//To print horizontal rectangle


public class HorizontalRectangle2
{
public static void main(String args[])
{
for (int i=1; i<4; i++)
{
for (int j=1; j<=7; j++)
{
[Link]("! ");
}
[Link]();
}
}
}

Output :
Program 47

Variable Description :

Variable Data Type Description

i int Outer Loop variable

j int Inner Loop variable

//To print vertical rectangle


public class VerticalRectanle3
{
public static void main(String args[])
{
for (int i=1; i<7; i++)
{
for (int j=1; j<=4; j++)
{
[Link]("! ");
}
[Link]();
}
}
}

Output :
Program 48

Variable Description :

Variable Data Type Description

i int Outer Loop variable

j int Inner Loop variable

//To print Right triangle


public class RightTrangle4
{
public static void main(String args[])
{
for (int i=1; i<5; i++)
{
for (int j=1; j<=i; j++)
{
[Link]("! ");
}
[Link]();
}
}
}

Output :
Program 49

Variable Description :

Variable Data Type Description

i int Outer Loop variable

j int Inner Loop variable

//To print Inverted Right Triangle


public class InvertedRightTrangle5
{
public static void main(String args[])
{
for (int i=5; i>=1; i--)
{
for (int j=i; j>=1; j--)
{
[Link]("! ");
}
[Link]();
}
}
}

Output:
Program 50

Variable Description :

Variable Data Type Description

i int Outer Loop variable

j int Inner Loop variable

You might also like