Computer Practise Paper 1 (Solved)
Computer Practise Paper 1 (Solved)
(THEORY)
(Ttwo Hours)
Answer to this paper must be written on the paper provided separately.
You will not be allowed to write answer for the first 15 minutes.
int
sample()
a=0;
Default constructor
int a;
sample(int n) //
Parameterized constructor
a=n;
compares
the sought key
(11) At each stage,
middle element of the array.
Ans. () Selection Sort
member
(i) Binary Search modifiers for
the
private [21
between public and
Ditterentiate
of a class.
declared to be private has its cess
accee
appliedimited tn
member
modifier: A class
private
member be ann
Ans. Private can a
outssde
means
to be public.
well as outside the class
block.
dedared
and y when the following statements
What are the values of x
Q.3 (a)
are executed?
boolean x=(a>b)?a:b;
should be:
boolean x=(a>b)?true: false; then,
x = true
y = 36
int x=4;x+=tx++)+(++x)+x;
Ans. x = 20
System.out.println(s.startsWith(s.substring(5,n);
System.out-println(s.charAt(2)==s.charAt(6));
Ans. False
True
( State the method that:
(i) Converts a string to a primitive float data type.
ii) Determines if the specified eharacter is an uppercase character.
Ans. ) Float.parseFloat(String argument)
(i) Character.is UpperCase(Character argument)
Ctate the data type and
g
values of a and b after
segment 1s executed,
the
following
String s1-"Computer", s2="Applications"; 2
a (s1.compare To
(s2);
b= (s1.equals (s2);
a is int and
Data type of value is 2.
1ns.
b
type of i Boolean and value
Data is false.
will be the
h)
string s="malayalam"
What following code output?
code
121
System.out.printi
ntln(s.indexOf('m'));
System.outprintlnís.lastIndexOf('m'));
Ans. 0
f = i ; System.out.println();}
whilei<=5)
System.out.println(f); i++
( -i;
t o the program given below, state the name and the value of the (2
or argument variable
) method argumernt
(ii) class variable
i ) local variable
class myClass {
static int x=7;
int y=2;
void main(String args[]){
public static
= n e w myClass();
my Class obj
System.outprintin(x);
obj.sampleMethod(5);
int a=6;
System.out.println(a);|
n with value
5.
Method argument variable -
5, 0) argument or
with value
Class variables x with value 7 and y
() -
int acc_num;
String title;
String author;
Scanner in =new
void input() Scanner(System.in);
System.out.println("Enter
title = in.next();
title of the
book");
System.out.println("Enter
author = in.next(); author name");
void compute()
int n,fine;
System.out.println("Fine to be
paid\t"+fine);
void display()
tln("Accession Number\t"+"Title\t"+"Author");
r i n t l n ( a c c _ n u m + " \ t " + t i t l e + " \ t " t a u t h o r ) ;
System.c
stem.out.print
class xyz
main(String
args[)
void.
static
pu bil
ublic
ob.input);
ob.compute);
ob.display0
V a r i a b l e D e s c r i p t i o n :
Description
Data Type
Variable Accession number.
int
book.
Title of the
A c c _ n u m
String book.
title name of the
Author
String the book.
late in returning
author
Number of days
int library
to the
Fine to be paid male
int income tax for
rate of
fine
table showing
hypothetical
below is a
Given of 65 year: Rs.
0.5 below the age Income
Tax in
citizens
Rs.
income (T) in
Taxable
Nil
7 1,60,000 10%
exceed 1,60,000) x
Does not (TI
-
than or
and less
1,60,000
than 7
Is greater + 34,000
equal t o 5 , 0 0 . 0 0 0 5,00,000) x
20%]
[(TI
-
than or
and less
7 5,00,000
than
s greater + 94,000
equal to 8,00,000 8,00,000) x
30%]
T(TI
-
F 8,00,000 income
s greater than and
taxable
female)
(male or
female,
display
gender is
to input
the age, or the gender gender
and the
a program than 65 years
te to 65 years
If the age is given
more
above.
Ans. import java.util.Scanner;
class incometax
System.out.println("Wrong category");
Variable Description:
Variable Data Type
Description
age Int
Age of the taxable person.
String Gender of the
person.
ti double Taxable income.
tax
double Tax to be
paid.
Q.6 Write a
program to accept
string. a
output the number of double letterConvert the string to uppercase. Coun
and
char cd;
Svstem.out.println("Enter a sentence"),
s t r = i n . n e x t L i n e ( ) ;
Estr.length();
for(i-0,i<l-1,it+)
cstr.charAt(i);
d-str.charAtfi+1);
if(c==d)
count++;
Variable Description:
of
i) a filled square
argument to draw ch.
stored in
side n using the character
that draws a
with two integer arguments
x, int y)
-
Example:
i) Input value of n=2, ch = "O
Output: O0
00
value of 2, y = 5
ii) Input x =
@@@@0®
Output:
(ii) Output:
*
*** [15
Ans. class pattern
void
polygon(int n, char ch)
int ij;
tori=1;i<=n;i++)
for(j=1j<=nj++)
System.out.print(ch);
System.out.println|);
void
polygon(int x, int y)
int ij;
fori=1;i<=x;i++)
for(j=1;j<=yj++)
System.out.print(®);
System.out.println();
void polygon()
int ij
for(i=1;i<=3;i++)
forj=1j<=ij++)
System.out.print("*);
System.out.printn();
Variable Description:
Variable Data Type
Description
n int Number of rows.
ch char Character to be
displayed.
int
Loop variables.
int
Length and breadth of rectangle.
Q.8 Using a
switch statement write a menu driven
i) Generate and display the first 10 terms of program to:
the Fibonacci series
0, 1, 1, 2, 3, 5..
The first two Fibonacci numbers are 0 and
1, and each subsequent number
is the sum of the previous two.
) Find the sum of the
Sample Input:
digits of an
integer that is
15390 input.
Sample Output: Sum of the
For an incorrect choice, an
digits =
18
case 1:
i-0;
j=1;
System.out.println("Elements of fibonacci series");
System.out.println(i);
System.out.println(j);
for(l-0;lk=8;1++)
k=i+j;
System.out.printn(k);
ij
j=k;
break;
case 2:
System.out.println("Enter a number");
n=in.nextlnt();
s=0;
while(n>0)
r=n%10;
S-S+r;
n=n/10;
1 int
Switch variable.
ch int
Number to input.
n int
number.
ctlij=in.next|);
std[1]=in.nextlnt();
cty=in.next();
f-0;
for(i=0;i<10;i++)
if(cty.equals(ct[i]))
f=1;
break;
iff-=1)
System.out.println("Search successful with city name\t"+ct[i]+"Std code
t+stdli]);
Variable Description:
City to be searched.
cty String name