Akshara Senthil 10B Computer Record Final
Akshara Senthil 10B Computer Record Final
Computer Applications
By: Akshara Senthil 10B Sishya OMR School
Sishya OMR School
Name:
Reg.No.:
CERTIFICATE
Teacher-in-charge
2.
Principal Examiners
Index
Serial No. Content Page No.
1 Index 1
2 Record 1 2&3
3 Record 2 4&5
4 Record 3 6&7
5 Record 4 8&9
6 Record 5 10-12
7 Record 6 13-15
8 Record 7 16 & 17
9 Record 8 18 & 19
10 Record 9 20 & 21
11 Record 10 22 & 23
12 Record 11 24-26
13 Record 12 27-29
14 Record 13 30 & 31
15 Record 14 32 & 33
16 Record 15 34-36
17 Record 16 37 & 38
18 Record 17 39 & 40
19 Record 18 41 & 42
20 Record 19 43 & 44
21 Record 20 45 & 46
22 Record 21 47 & 48
23 Record 22 49 & 50
24 Record 23 51 & 52
25 Record 24 53 & 54
26 Record 25 55 & 56
Record 1
Aim
Write a program to calculate the special discount in a laptop shop with the following
specifications:
Class name: laptop
Instance variables: name, price, dis, amt
Methods:
1. Accept details of the customer
2. To compute discount as per the following table:
upto 25,000 5%
25001-50000 7.5%
50001-100000 10%
>100000 15%
3. Display name, dis, and amt
Source Code
import java.util.*;
public class laptop
{
String name;
double price,dis,amt;
public static void main(String args[])
{
laptop object=new laptop();
object.accept();
object.calculate();
object.display();
}
void accept()
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter your name: ");
name=obj.nextLine();
System.out.println("Enter price: ");
price=obj.nextInt();
}
void calculate()
{
if(price<=25000)
{
dis=(5.0/100.0)*price;
amt=price-dis;
}
else if(price>=25001&&price<=50000)
{
dis=(7.5/100.0)*price;
amt=price-dis;
}
else if(price>=50001&&price<=100000)
{
dis=(10.0/100.0)*price;
amt=price-dis;
}
else
{
dis=(15.0/100.0)*price;
amt=price-dis;
}
}
void display()
{
System.out.println("Name of customer: " + name);
System.out.println("Discount on price: " + dis);
System.out.println("Amount with discount: " + amt);
}
}
Input/Output
Record 2
Aim
Write a program to accept a number and check whether it is a spy number or not.
Spy number:- A number whose sum of the digits equals the product of the digits.
Source Code
import java.util.*;
public class record2tenthgrade
{
public static void main(String args[])
{
int n,s=0,p=1,rem=0;
System.out.println("Enter a number to check whether it is a spy number or not: ");
Scanner obj = new Scanner(System.in);
n=obj.nextInt();
while(n!=0)
{
rem=n%10;
n=n/10;
s=s+rem;
p=p*rem;
}
if(s==p)
System.out.println("Spy number");
else
System.out.println("Not a spy number");
}
}
Variable Description Table
Name Data Type Description
n int To accept the number to be
checked
s int To calculate and store the
sum of the digits of the
number
p int To calculate and store the
product of the digits of the
number
rem int To help in calculating the
sum and product of the
digits
Input/Output
Record 3
Aim
Given below is a hypothetical table showing the rate of income tax for a male citizen of an
age below 65 years:
Taxable income Income tax
does not exceed 2,50,000 nil
more than 2,50,000 but less than or equal (TI-2,50,000)*10%
to 5,00,000
greater than 5,00,000 but less than or equal ((TI-5,00,000)*20%)+34,000
to 10,00,000
more than 10,00,000 ((TI-10,00,000)*30%)+94000
Write a program to input the age, gender, taxable income of a person. If the age of a person
is above 65 years or they are of the female gender, display 'Wrong Category'. If the age is
less than or equal to 65 years and gender is male, compute and display the income tax to be
paid.
Source Code
import java.util.*;
public class record3tenthgrade
{
public static void main(String args[])
{
double age,ti,am=0;
char gender;
Scanner obj = new Scanner(System.in);
System.out.println("Input your age and taxable income");
age=obj.nextDouble();
ti=obj.nextDouble();
System.out.println("Enter 'M' for male and 'F' for female");
gender=obj.next().charAt(0);
if(age<65&&gender=='M')
{
if(ti<=250000.0)
{
am=0;
}
else if(ti>250000.0&&ti<=500000.0)
{
am=(ti-250000.0)*(10.0/100.0);
}
else if(ti>500000.0&&ti<+1000000.0)
{
am=((ti-500000.0)*(20.0/100.0))+34000.0;
}
else if(ti>1000000.0)
{
am=((ti-1000000.0)*(30.0/100.0))+94000.0;
}
}
else if(age>=65||gender=='F')
{
System.out.println("Wrong category");
}
System.out.println("Total amount is: " + am);
}
}
Variable Description Table
Name Data Type Description
age double To accept the age of the
taxpayer
ti double To accept the taxable
income of the taxpayer
am double To calculate, store, and
display the total amount of
income tax to be paid by the
taxpayer
gender char To accept the gender of the
taxpayer
Input/Output
Record 4
Aim
Write a program to enter two numbers and check whether they are co-prime or not.
Co-prime numbers:- They are numbers whose only common factor is one.
Source Code
import java.util.*;
public class record4tenthgrade
{
public static void main(String args[])
{
int a,b,j=0;
Scanner obj = new Scanner(System.in);
System.out.println("Enter two numbers to check if they are co-prime or not: ");
a=obj.nextInt();
b=obj.nextInt();
for(int i=1;i<=a||i<=b;i++)
{
if(a%i==0&&b%i==0)
++j;
else
continue;
}
if(j==1)
System.out.println("They are co-prime");
else
System.out.println("They are not co-prime");
}
}
Source Code
import java.util.*;
public class record5tenthgrade
{
public static void main(String args[])
{
double n,s=0,s2=1,b=1,c=0;
int a,choice,exp=1;
Scanner obj = new Scanner(System.in);
System.out.println("Input till which term you want the series to go on");
n=obj.nextDouble();
System.out.println("Enter the value of a for the first case");
a=obj.nextInt();
System.out.println("Enter 1 for series 1 and 2 for series 2");
choice=obj.nextInt();
switch(choice)
{
case 1:
{
for(int i=1;i<=n;i++)
{
if(i%2==0)
{
s=s-Math.pow(a,exp);
}
else
{
s=s+Math.pow(a,exp);
}
exp=exp+2;
}
System.out.println("The sum of the series is: " + s);
break;
}
case 2:
{
for(int k=2;k<=n;k++)
{
b=1;
c=0;
for(int j=1;j<=k;j++)
{
b=b*j;
c=c+j;
}
s2=s2+(b/c);
}
System.out.println("The sum of the series is: " + s2);
break;
}
default:
System.out.println("Wrong input");
}
}
}
Data members:
int prv, pre: To accept the previous and present meter readings
int call: To store the calls made (pre-prv)
String name: To store the name of the consumer
double amt: To store the amount
double total: To store the total amount to be paid
Member functions:
void input(): Stores the previous reading, present reading, and name of the consumers
void call(): Calculates the amount and the total amount to be paid
void display(): Displays the name of the consumer, calls made, and the total amount to be
paid
Write a program to compute the monthly bill to be paid according to the given instructions:
Calls made Rate
Up to 100 calls Nill
For the next 100 calls 2 rupees per call
For the next 200 calls 3 rupees per call
More than 400 calls 4 rupees per call
However, every consumer must pay 180 rupees per month as monthly rent for the service.
Source Code
import java.util.*;
public class Telephone
{
int call,prv,pre;
String name;
double amt=0,total=0;
public static void main(String args[])
{
Telephone object=new Telephone();
object.input();
object.call();
object.display();
}
void input()
{
Scanner obj = new Scanner(System.in);
System.out.println("Input the previous meter reading: ");
prv=obj.nextInt();
System.out.println("Input the present meter reading: ");
pre=obj.nextInt();
obj.nextLine();
System.out.println("Input your name: ");
name=obj.nextLine();
}
void call()
{
call=pre-prv;
if(call<=100)
{
amt=0;
}
else if(call>100&&call<=200)
{
amt=(double)(call-100.0)*2.0+(100.0*0);
}
else if(call>200&&call<=400)
{
amt=(double)(call-200.0)*3.0+(100.0*2.0)+(100.0*0);
}
else if(call>400)
{
amt=(double)(call-400.0)*4.0+(200.0*3.0)+(100.0*2.0)+(100.0*0);
}
total=amt+180.0;
}
void display()
{
System.out.println("Name of the consumer\tCalls made\tAmount");
System.out.print(name+"\t\t\t"+call+"\t\t"+total);
}
}
Variable Description Table
Name Data Type Description
call int To store the number of calls
prv int To store previous meter
reading
pre int To store present meter
reading
name String To store the name of the
consumer
amt double To store the amount of
money to be paid by
consumer
total double To store the amount of
money to be paid by the
consumer including the
monthly service rent
Input/Output
Record 7
Aim
Write a program to accept 10 different numbers in Single-Dimensional Array and enter a
searching element and display whether the number is present or not using a linear search.
Display whether the number is present or not and display the location of the element.
Source Code
import java.util.*;
public class record7tenthgrade
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter the number to find");
int choice=obj.nextInt();
int a[]=new int[10];
for(int i=0;i<10;i++)
{
System.out.println("Enter: " + (i+1) + " number");
a[i]=obj.nextInt();
}
for(int j=0;j<10;j++)
{
if(choice==a[j])
{
System.out.println("The number is present at: " + (j+1) + " location");
break;
}
if(j==9)
System.out.println("The number is not present");
}
}
}
Variable Description Table
Variable Data Type Description
choice int To input the number to
check if it is an element of
the array
i int To be the control variable of
the first loop and to input
the members of the array
j int To be the control variable of
the second variable and to
check whether the given
element is a part of the
array or not
Input/Output
Record 8
Aim
Write a program to accept 10 different numbers in a Single-Dimensional Array and enter a
searching element and display whether the number is present or not using binary search.
Source Code
import java.util.*;
public class record8tenthgrade
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter the number to find: ");
int search=obj.nextInt();
int a[]=new int[10];
int lb=0,ub=9;
for(int i=0;i<10;i++)
{
System.out.println("Enter the: " + (i+1) + " number. A request to the user to enter the
number in a sorted array arranged ascendingly.");
a[i]=obj.nextInt();
}
while(lb<=ub)
{
int mid=(lb+ub)/2;
if(a[mid]==search)
{
System.out.println("The number is present at the : " + (mid+1) + " location");
break;
}
else if (a[mid]>search)
{
ub=mid-1;
}
else if(a[mid]<search)
{
lb=mid+1;
}
}
if(lb>ub)
System.out.println("The number is not found");
}
}
Variable Description Type
Variable Data Type Description
search int To input the search element
lb int To store the lower limit of
the array for calculations
ub int To store the upper limit of
the array for calculations
i int To be the control variable of
the first loop and to input
the elements of the array
mid int To store the middle value of
the loop
Input/Output
Record 9
Aim
Write a program to accept an array of numbers from a user in any order and arrange and
print the numbers in ascending order using Bubble Sort.
Source Code
import java.util.*;
public class record9tenthgrade
{
public static void main(String args[])
{
int temp=0;
Scanner obj = new Scanner(System.in);
int a[]=new int[10];
for(int k=0;k<10;k++)
{
System.out.println("Enter the " + (k+1) + " number.");
a[k]=obj.nextInt();
}
for(int i=0;i<10;i++)
{
for(int j=0;j<9;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
else
continue;
}
}
System.out.println("The series in ascending order is as follows: ");
for(int l=0;l<10;l++)
{
System.out.println("The " + (l+1) + " term is: " + a[l]);
}
}
}
Variable Description Table
Name Data Type Description
temp int To store the value of a
variable in the array
temporarily to switch places
with another variable in the
array
k int To be the control variable of
the loop that inputs the
array values
i int To be the control variable of
the outer loop that sorts the
array values
j int To be the control variable of
the inner loop that sorts the
array values
l int To be the control variable of
the loop that displays the
arranged array values in
ascending order
Input/Output
Record 10
Aim
Write a program to accept an array of numbers from a user in any order and arrange and
print the numbers in ascending order using Selection Sort.
Source Code
import java.util.*;
public class record10tenthgrade
{
public static void main(String args[])
{
int temp;
Scanner obj = new Scanner(System.in);
int a[]=new int[10];
for(int k=0;k<10;k++)
{
System.out.println("Enter the: " + (k+1) + " number.");
a[k]=obj.nextInt();
}
for(int i=0;i<10;i++)
{
int x=i;
for(int j=i+1;j<10;j++)
{
if(a[j]<a[x])
{
x=j;
}
}
temp=a[i];
a[i]=a[x];
a[x]=temp;
}
System.out.println("The series in ascending order is as follows: ");
for(int l=0;l<10;l++)
{
System.out.println("The " + (l+1) + " term is: " + a[l]);
}
}
}
Variable Description Table
Name Data Type Description
temp int To store the value of a
variable in the array
temporarily to switch places
with another variable in the
array
k int To be the control variable of
the loop that inputs the
array values
i int To be the control variable of
the outer loop that sorts the
array values
x int To help in the arranging of
variables by finding which
variable of the array is least,
second least, and so on
j int To be the control variable of
the inner loop that sorts the
array values
l int To be the control variable of
the loop that displays the
arranged array values in
ascending order
Input/Output
Record 11
Aim
Write a program to accept the names and total marks of 'N' number of students in two
single subscript arrays, which are name[] and totalmarks[]. Calculate and print using
methods:
1. The average of the total marks obtained by 'N' number of students, that is
Average = Sum of marks/'N' number of students
2. The deviation of each student's total marks from the average, that is
Deviation = Total marks scored by each student - average of all students' marks
Source Code
import java.util.*;
public class record11tenthgrade
{
int avg,N;
String name[];
int totalmarks[];
public static void main(String args[])
{
record11tenthgrade object = new record11tenthgrade();
object.input();
object.average();
object.deviation();
}
void input()
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter the number of students: ");
N=obj.nextInt();
obj.nextLine();
name=new String[N];
totalmarks=new int[N];
for(int i=0;i<N;i++)
{
System.out.println("Enter the: " + (i+1) + " students' name.");
name[i]=obj.nextLine();
System.out.println("Enter the: " + (i+1) + " students' marks.");
totalmarks[i]=obj.nextInt();
obj.nextLine();
}
}
void average()
{
int s=0;
for(int k=0;k<N;k++)
{
s=s+totalmarks[k];
}
avg=s/N;
System.out.println("The total average is: " + avg);
}
void deviation()
{
int dev;
for(int l=0;l<N;l++)
{
dev=totalmarks[l]-avg;
System.out.println("Deviation of: " + name[l] + " students' marks is: " + dev);
}
}
}
Source Code
import java.util.*;
public class courier
{
String name, address;
double weight, bill;
char type;
public static void main(String args[])
{
courier object = new courier();
object.accept();
object.calculate();
object.print();
}
void accept()
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter customer name: ");
name=obj.nextLine();
System.out.println("Enter customer address: ");
address=obj.nextLine();
System.out.println("Enter courier weight: ");
weight=obj.nextDouble();
System.out.println("Enter 'D' for domestic courier and 'I' for international courier");
type=obj.next().charAt(0);
}
void calculate()
{
if(type=='D')
{
if(weight<=5.0)
{
bill=800.0*weight;
}
else if(weight>5.0&&weight<=10.0)
{
bill=(weight-5.0)*700.0+(5.0*800.0);
}
else if(weight>10.0)
{
bill=(weight-10.0)*500+(5.0*700)+(5.0*800);
}
}
else if(type=='I')
{
if(weight<=5.0)
{
bill=(800.0*weight)+1500.0;
}
else if(weight>5.0&&weight<=10.0)
{
bill=((weight-5.0)*700.0+(5.0*800.0))+1500.0;
}
else if(weight>10.0)
{
bill=((weight-10.0)*500+(5.0*700)+(5.0*800))+1500.0;
}
}
else
{
System.out.println("Wrong input");
}
}
void print()
{
System.out.println("The name of customer is: " + name);
System.out.println("The address of customer is: " + address);
System.out.println("The weight of the courier is: " + weight);
if(type=='D')
System.out.println("The type is domestic");
else if(type=='I')
System.out.println("The type is international");
System.out.println("The final bill of the courier is: " + bill);
}
}
Input/Output
Record 13
Aim
Write a program to store six elements in an array P[] and four elements in an array Q[] to
produce a third array R[] containing all the elements of P and Q.
Source Code
import java.util.*;
public class record13tenthgrade
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
int P[]=new int[6];
int Q[]=new int [4];
int R[]=new int[10];
for(int i=0;i<6;i++)
{
System.out.println("Enter the: " + (i+1) + " term of the first array");
P[i]=obj.nextInt();
}
for(int j=0;j<4;j++)
{
System.out.println("Enter the: " + (j+1) + " term of the second array");
Q[j]=obj.nextInt();
}
for(int k=0;k<6;k++)
{
R[k]=P[k];
}
for(int l=0;l<4;l++)
{
R[l+6]=Q[l];
}
for(int m=0;m<10;m++)
{
System.out.println("The " + (m+1) + " term of the newly produced array is: " + R[m]);
}
}
}
Variable Description Table
Input/Output
Record 14
Aim
Write a program to store numbers in a 4x4 matrix and find the transpose of the matrix.
Source Code
import java.util.*;
public class record14
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
int a[][]=new int[4][4];
int b[][]=new int[4][4];
System.out.println("Enter 16 matrix elements: ");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=obj.nextInt();
b[j][i]=a[i][j];
}
}
System.out.println("Original array is: ");
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
System.out.print(a[k][l]);
}
System.out.println();
}
System.out.println("New array is: ");
for(int m=0;m<4;m++)
{
for(int n=0;n<4;n++)
{
System.out.print(b[m][n]);
}
System.out.println();
}
}
}
Variable Description Table
Name Data Type Description
i int To be the loop control variable
of outer loop 1
j int To be the loop control variable
of inner loop 1
k int To be the loop control variable
of outer loop 2
l int To be the loop control variable
of inner loop 2
m int To be the loop control variable
of outer loop 3
n int To be the loop control vairable
of inner loop 3
Input/Output
Record 15
Aim
Write a program to store numbers in a 4x4 matrix in a 2 Dimensional Array. Find the sum of the
numbers of each row and each column, left diagonal, and right diagonal.
Source Code
import java.util.*;
public class record15
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter 16 array elements: ");
int a[][]=new int[4][4];
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=obj.nextInt();
}
}
for(int i1=0;i1<4;i1++)
{
int s=0;
for(int j1=0;j1<4;j1++)
{
s=s+a[i1][j1];
}
System.out.println("Sum of " + (i1+1) + " row is " + s);
}
for(int i2=0;i2<4;i2++)
{
int s1=0;
for(int j2=0;j2<4;j2++)
{
s1=s1+a[j2][i2];
}
System.out.println("Sum of " + (i2+1) + " column is " + s1);
}
int s2=0;
for(int i3=0;i3<4;i3++)
{
for(int j3=0;j3<4;j3++)
{
if(i3==j3)
s2=s2+a[i3][j3];
}
}
System.out.println("Sum of left diagonal is " + s2);
int s3=0;
for(int i4=0;i4<4;i4++)
{
for(int j4=0;j4<4;j4++)
{
if((i4+j4)==3)
{
s3=s3+a[i4][j4];
}
}
}
System.out.println("Sum of right diagonal is " + s3);
}
}
Source Code
import java.util.*;
public class overloading
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
overloading object = new overloading();
System.out.println("Enter the base and height of a parallelogram: ");
double b1 =obj.nextDouble();
double h1=obj.nextDouble();
System.out.println("Enter the two diagonals of a rhombus: ");
int diagonal11=obj.nextInt();
int diagonal21=obj.nextInt();
System.out.println("Enter the two parallel sides of a trapezium then its height: ");
int d1=obj.nextInt();
int e1=obj.nextInt();
int height1=obj.nextInt();
object.area(b1,h1);
object.area(diagonal11,diagonal21);
object.area(d1,e1,height1);
}
void area(double b,double h)
{
double area=b*h;
System.out.println("The area of the parallelogram is: " + area);
}
void area(int diagonal1,int diagonal2)
{
double area=(0.5)*(double)diagonal1*(double)diagonal2;
System.out.println("The area of the rhombus is " + area);
}
void area(int d, int e, int height)
{
double area=(0.5)*height*(d+e);
System.out.println("The area of the parallelogram is " + area);
}
}
Variable Description Table
Name Data Type Description
b1 double To pass parallelogram breadth
to the method
h1 double To pass parallelogram height
to the method
diagonal11 int To pass rhombus diagonal to
the method
diagonal21 int To pass rhombus diagonal to
the method
d1 double To pass trapezium side to the
method
e1 double To pass trapezium side to the
method
height1 double To pass trapezium height to
the method
b double To calculate area of
parallelogram
h double To calculate area of
parallelogram
diagonal1 int To calculate area of rhombus
diagonal2 int To calculate area of rhombus
d double To calculate area of trapezium
e double To calculate area of trapezium
height double To calculate area of trapzium
area double To store and display areas of
parallelogram, rhombus, and
trapzium
Input/Output
Record 17
Aim
A metropolitan hotel has 5 floors numbered from 0-4, each floor having 5 rooms. Using a single
subscripted variable for the name of the customers and double subscripted variable R(F,I) where F
and I represent the floors and room numbers respectively. Write a program for the room allocation
work. The proram should automatically record the names of the customers and the room numbers.
Source Code
import java.util.*;
public class record17
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
String R[][]=new String[5][5];
String a[]=new String[25];
int c=0;
System.out.println("Enter the name of the customer in every room: ");
for(int i=0;i<25;i++)
{
a[i]=obj.nextLine();
}
for(int F=0;F<5;F++)
{
for(int I=0;I<=4;I++)
{
R[F][I]=a[c];
c=c+1;
}
}
for(int F=0;F<5;F++)
{
for(int I=0;I<=4;I++)
{
System.out.println(R[F][I] + " stays on the " + F + " floors and " + (I+1) + " room");
}
}
}
}
Write a main program to create an object of the class and call the above member methods.
Source Code
import java.util.*;
public class MovieMagic
{
int year;
String title;
float rating;
public static void main(String args[])
{
MovieMagic object = new MovieMagic();
object.accept();
object.display();
}
MovieMagic()
{
year=0;
title=" ";
rating=0;
}
void accept()
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter the name of the movie: ");
title=obj.nextLine();
System.out.println("Enter the year of the movie: ");
year=obj.nextInt();
System.out.println("Enter the rating of the movie where minimum is 0.0 and maximum is
5.0");
rating=obj.nextFloat();
}
void display()
{
System.out.println("The title of the movie is: " + title);
if(rating>=0.0&&rating<=2.0)
System.out.println("Flop");
else if(rating>=2.1&&rating<=3.4)
System.out.println("Semi-Hit");
else if(rating>=3.5&&rating<=4.5)
System.out.println("Hit");
else if(rating>=4.6&&rating<=5.0)
System.out.println("Super Hit");
}
}
Input/Output
Record 19
Aim
Define a class temperature described below:
Instance Variables:
double max: To store maximum temperature
double min: To store minimum temperature
Methods:
1. A parameterized constructor to input the maximum and minimum temperatures in a day in
°C
2. To compute the maximum and minimum temperatures in °F
3. To display the maximum and minimum temperatures in °F
Write a main method to create on object of a class to call the member methods.
Source Code
import java.util.*;
public class temperature
{
double max;
double min;
public static void main(String args[])
{
temperature object = new temperature();
object.compute();
object.display();
}
temperature()
{
Scanner obj = new Scanner(System.in);
System.out.println("Input maximum temperature in °C: ");
max=obj.nextDouble();
System.out.println("Input minimum temperature in °C: ");
min=obj.nextDouble();
}
void compute()
{
max=((9*max)/5)+32;
min=((9*min)/5)+32;
}
void display()
{
System.out.println("The maximum temperature in °F is: " + max);
System.out.println("The minimum temperature in °F is: " + min);
}
}
Variable Description Table
Name Data Type Description
max double To store and display maximum
temperatures in °C and °F
min double To store and display minimum
temperature in °C and °F
Input/Output
Record 20
Aim
Write a program to accept a number and check whether it is a Niven number.
Niven numbers:- They are numbers that are divisible by the sum of their digits.
Source Code
import java.util.*;
public class record20
{
public static void main(String args[])
{
int n,s=0,rem=0;
Scanner obj = new Scanner(System.in);
System.out.println("Enter a number to figure out whether it is a Niven number or not: ");
n=obj.nextInt();
int temp=n;
while(temp>0)
{
rem=temp%10;
temp=temp/10;
s=s+rem;
}
if(n%s==0)
System.out.println(n + " is a Niven number");
else
System.out.println(n + " is not a Niven number");
}
}
Source Code
import java.util.*;
public class Record21
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter a string: ");
String a = obj.nextLine();
String b = "";
for (int i = 0; i < a.length(); i++)
{
String c = a.substring(i, i + 1);
if (c.compareTo("Z") > 0)
{
c = c.toUpperCase();
}
else
{
c = c.toLowerCase();
}
b = b.concat(c);
}
System.out.println(b);
}
}
Variable Description Table
Name Data Type Description
a String To input the String
b String To store and output the new
String
i int To be the loop control variable
c String To compare the String case one
at a time
Input/Output
Record 22
Aim
Write a program to accept a sentence in the lower case and convert the first letter of each word of
the sentence in upper case. Display the new sentence.
Source Code
import java.util.*;
public class record22
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.println("Input a string in lower case: ");
String a=obj.nextLine();
a=" "+a;
String c="";
char b=' ';
for(int i=0;i<a.length()-1;i++)
{
if(a.charAt(i)==' ')
b=Character.toUpperCase(a.charAt(i+1));
else
b=a.charAt(i+1);
c=c+b;
}
System.out.println(c);
}
}
Source Code
import java.util.*;
public class record23
{
public static void main(String args[])
{
char a[]={'B','L','U','E','J'};
int z=0;
for(int i=0;i<=4;i++)
{
for(int j=0;j<i;j++)
{
System.out.print(" ");
}
for(int k=i;k<=4;k++)
{
System.out.print(a[z] + " ");
z=z+1;
}
z=0;
System.out.println();
}
}
}
Variable Description Table
Name Data Type Description
z int To control the index of the
array element to be printed
i int To be the loop control variable
of the outer loop
j int To be the loop control variable
of the first inner loop
k int To be the loop control variable
of the second inner loop
Input/Output
Record 24
Aim
Write a menu-driven program to display the pattern of the string entered by the user. If the user
entered the choice ‘F’ it displays the first character of each word. If the choice is ‘L’, it will display the
last character of the word.
Source Code
import java.util.*;
public class record24
{
public static void main(String args[])
{
Scanner obj = new Scanner(System.in);
System.out.println("Enter a string: ");
String a=obj.nextLine();
a=" "+a;
String b=a + " ";
System.out.println("Enter choice 'F' to display the first character of each word. Enter
choice 'L' to display the last character of each word.");
char choice=obj.next().charAt(0);
switch(choice)
{
case 'F':
{
for(int i=0;i<a.length()-1;i++)
{
if(a.charAt(i)==' ')
System.out.println(a.charAt(i+1));
}
break;
}
case 'L':
{
for(int j=0;j<b.length()-1;j++)
{
if(b.charAt(j+1)==' ')
System.out.println(b.charAt(j));
}
break;
}
default:
System.out.println("Wrong choice");
}
}
}
Input/Output
Record 25
Aim
Write a program to initialize the 7 wonders of the world along with their locations in 2 different
arrays. Search for a name of the country input by the user. If found, display the country along with
its wonder or display “Sorry, not found”.
Source Code
import java.util.*;
public class record25
{
public static void main(String args[])
{
String a[]={"Great wall of China","Chichen Itza","Petra","Machu Pichu","Christ the
Redeemer","Colosseum","Taj Mahal"};
String b[]={"China","Mexico","Jordan","Peru","Brazil","Italy","India"};
Scanner obj = new Scanner(System.in);
System.out.println("Enter the name of a country: ");
String j=obj.nextLine();
int count=0;
for(int i=0;i<=6;i++)
{
if(j.equalsIgnoreCase(b[i])==true)
{
System.out.println(a[i] + " is located in " + b[i]);
count=count+1;
}
}
if(count==0)
System.out.println("Sorry, not found");
}
}