0% found this document useful (0 votes)
4 views8 pages

Java Programs for Half-Yearly Exams

The document contains six Java programs, each demonstrating different functionalities. Program 1 checks if a number is an Adam number, Program 2 provides a menu for calculating the sum of a series or printing a pattern, Program 3 calculates loan interest based on time, Program 4 determines if a number is Xylem or Phloem, Program 5 calculates a new salary based on experience, and Program 6 demonstrates method overloading. Each program utilizes user input and performs specific calculations or outputs.

Uploaded by

manyag366
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)
4 views8 pages

Java Programs for Half-Yearly Exams

The document contains six Java programs, each demonstrating different functionalities. Program 1 checks if a number is an Adam number, Program 2 provides a menu for calculating the sum of a series or printing a pattern, Program 3 calculates loan interest based on time, Program 4 determines if a number is Xylem or Phloem, Program 5 calculates a new salary based on experience, and Program 6 demonstrates method overloading. Each program utilizes user input and performs specific calculations or outputs.

Uploaded by

manyag366
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

Solution of Half-Yearly Exam programs

Program 1
import [Link].*;
public class Adam
{
void main()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter any number");
int num=[Link]();
int sq=num*num;
int rev=0,rev1=0;
int rem,rem1;
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
int sq2=rev*rev;
while(sq2>0)
{
rem1=sq2%10;
rev1=rev1*10+rem1;
sq2=sq2/10;
}
if(sq==rev1)
{
[Link]("Number is Adam");
}
else
{
[Link]("Number is not Adam");
}
}
}

Program 2
import [Link].*;
public class MenuDriven
{
void main()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter 1 for sum of series and 2 for Pattern");
int choice=[Link]();
switch(choice)
{
case 1:
[Link]("Enter the number of terms in the series?");
int n=[Link]();
[Link]("Enter the value of variable x?");
int x=[Link]();
double sum=0.0d;
for(int i=1;i<=n;i++)
{
sum=sum+(double)i/([Link](x,i));
}
[Link]("The sum of the series is ="+sum);
break;
case 2:
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
[Link](i+" ");
}
for(int k=4;k>=i;k--)
{
[Link]("* ");
}
[Link]();
}
break;
default:
[Link]("Wrong choice");
}
}
}

Program 3
import [Link].*;
public class Loan
{
int time;
double principal,rate,amt,interest;
void accept()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter the time");
time=[Link]();
[Link]("Enter the principal");
principal=[Link]();
}
void calculate()
{
if(time<=5)
{
rate=10;
}
else if(time>5 && time<=10)
{
rate=12;
}
else
{
rate=15;
}
amt=principal*([Link]((1+rate/100),time));
interest=amt-principal;
}
void display()
{
[Link]("The amount to be paid is ="+amt);
[Link]("The interest to be paid is ="+interest);
}
void main()
{
Loan ob=new Loan();
[Link]();
[Link]();
[Link]();
}
}

Program 4
import [Link].*;
public class Xylem_Phloem
{
void main()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter a number");
int num=[Link]();
int extreme1=num%10;
int num1=num/10;
int rem,rem1,rev=0;
int sum_mean=0,sum_extreme;
while(num1>0)
{
rem=num1%10;
rev=rev*10+rem;
num1=num1/10;
}
int extreme2=rev%10;
int r_digit=rev/10;
while(r_digit>0)
{
rem1=r_digit%10;
sum_mean=sum_mean+rem1;
r_digit=r_digit/10;
}
sum_extreme=extreme1+extreme2;
if(sum_extreme==sum_mean)
{
[Link]("Number is Xylem");
}
else
{
[Link]("Number is Phloem");
}
}
}

Program 5
import [Link].*;
public class Upgrade
{
String name;
int bas,expn;
double inc,nbas;
Upgrade()
{
name="";
bas=0;
expn=0;
inc=0.0d;
nbas=0.0d;
}
void input()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter Employee's name?");
name=[Link]();
[Link]("Enter the basic salary of the Employee?");
bas=[Link]();
[Link]("Enter the length of service of the employee?");
expn=[Link]();
}
void increment()
{
if(expn<=3)
{
inc=5000+((10*bas)/100);
}
else if(expn>3 && expn<=5)
{
inc=5500+((12*bas)/100);
}
else if(expn>5 && expn<=10)
{
inc=7000+((15*bas)/100);
}
else
{
inc=8000+((20*bas)/100);
}
nbas=bas+inc;
}
void display()
{
[Link]("Employee's Name\t\tBasic Salary\t\tExperience\t\tNew
Salary");
[Link](name+"\t\t"+bas+"\t\t"+expn+"\t\t\t"+nbas);
}
void main()
{
Upgrade ob=new Upgrade();
[Link]();
[Link]();
[Link]();
}
}

Program 6
public class Overload
{
double show(double r,double h)
{
double pi=3.14;
double V=pi*r*r*h;
return V;
}
void show(int r,int c)
{
int i=1;
while(i<=r)
{
int j=1;
int x=2;
while(j<=c)
{
[Link](x+" ");
x=x+2;
j++;
}
i++;
[Link]();
}
}
void show(int x,int y,char ch)
{
if(ch=='Q')
{
[Link](x/y);
}
else if(ch=='R')
{
[Link](x%y);
}
else
{
[Link]("Enter correct choice as character");
}
}
}

You might also like