Final Board Papers Solutions 2005-2019

Download as pdf or txt
Download as pdf or txt
You are on page 1of 92

1 Board Papers Solution (Section B)

Board Paper 2005

Q-4 import java.io.*;


class Employee
{
double basic;
public static void main(String [] args) throws IOException
{
Employee obj = new Employee(); // creating object of the class to use
// instance variable basic
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter basic salary : ");
String v1 = in.readLine();
obj.basic = Double.parseDouble(v1);
double da = obj.basic*25/100;
double hra = obj.basic*15/100;
double pf = obj.basic*8.33/100;
double net = obj.basic + da + hra;
double gross = net - pf;
System.out.println("Gross pay = " + gross);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


2 Board Papers Solution (Section B)

Q-5 import java.io.*;


class P2005_5
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter string : ");
String s = in.readLine();

int l = s.length();
System.out.println("No of characters = " + l);
int i, cnt = 0;
String rev ="";
for(i = l-1; i >= 0; i--)
{
char ch = s.charAt(i);
rev = rev + ch;
switch(ch)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u':
cnt++;
}
}
System.out.println("No of vowels is " + cnt);
System.out.println("Reverse is " + rev);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


3 Board Papers Solution (Section B)

Q-6 import java.io.*;


class Menu
{
public static void area()throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("MENU");
System.out.println("1. Area of circle");
System.out.println("2. Area of square");
System.out.println("3. Area of rectangle");
System.out.println("Enter choice : ");
String v1 = in.readLine();
int ch = Integer.parseInt(v1);
switch(ch)
{
case 1:
System.out.print("Enter radius : ");
String v2 = in.readLine();
int rad = Integer.parseInt(v2);
double areac = Math.PI * Math.pow(rad,2);
System.out.println("Area of a circle is " + areac);
break;
case 2:
System.out.print("Enter side : ");
String v3 = in.readLine();
int s = Integer.parseInt(v3);
double areas = Math.pow(s,2);
System.out.println("Area of a square is " + areas);
break;
case 3:
System.out.print("Enter length and breadth : ");
String v4 = in.readLine();
int l = Integer.parseInt(v4);
String v5 = in.readLine();
int b = Integer.parseInt(v5);
double arear = l * b;
System.out.println("Area of a rectangle is " + arear);
break;
default:
System.out.println("INVALID CHOICE");
}
}
public static void main(String [] args) throws IOException
{
area();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


4 Board Papers Solution (Section B)

Q-7 class Bubble


{
public static void main(String [] args)
{
int x[] = {5,3,8,4,9,2,1,12,98,16};
int i,j,t;
int len = x.length;
for(i = 0; i < len-1; i++)
{
for(j=0;j < len-1-i; j++)
{
if(x[j] > x[j+1])
{
t = x[j];
x[j] = x[j+1];
x[j+1]= t;
}
}
}
for(i = 0; i < len; i++)
{
System.out.println(x[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


5 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Counter
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
int sumpe = 0,sumpo = 0, sumn = 0, x;
do
{
System.out.print("Enter number : ");
String v1 = in.readLine();
x = Integer.parseInt(v1);
if(x < 0)
sumn = sumn + x;
else
if(x > 0 && x % 2 == 0)
sumpe = sumpe + x;
else
if(x > 0 && x % 2 != 0)
sumpo = sumpo + x;
}
while(x!=0);
System.out.println("Sum of Positive even numbers : " + sumpe);
System.out.println("Sum of Positive odd numbers : " + sumpo);
System.out.println("Sum of Negative numbers : " + sumn);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


6 Board Papers Solution (Section B)

Q-9 import java.io.*;


class LinearSearch
{
public static void main(String [] args)throws IOException
{
String name[] = {"AMIT", "AJAY", "AMAN", "ANIL", "APURVA"};
long ph[] = {1234567,7895641,9874561,7457112,9678412};
int i, flag = 0;
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter name to be searched : ");
String value = in.readLine();
for(i = 0; i < 5; i++)
{
if(value.equalsIgnoreCase(name[i]))
{
System.out.println("Search Successful");
System.out.println("Name is " + name[i]);
System.out.println("Telephone no is "+ ph[i]);
flag = 1;
break;
}
}
if(flag == 0)
System.out.println("Name not enlisted ");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


7 Board Papers Solution (Section B)

Board Paper 2006


Q-4 import java.io.*;
class SumEvenOdd
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter value of n : ");
String v1 = in.readLine();
int n = Integer.parseInt(v1);
int i , sume = 0 , sumo = 0;
for(i = 1; i <= n ; i++)
{
if(i % 2 == 0)
sume = sume + i;
else
sumo = sumo + i;
}
System.out.println("Sum of even nos is "+ sume);
System.out.println("Sum of odd nos is "+ sumo);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


8 Board Papers Solution (Section B)

Q-5 import java.io.*;


class ClothShow
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter total cost : ");
String v1 = in.readLine();
double c = Double.parseDouble(v1);
double dis = 0.0;
if(c <= 2000)
dis = c *5/100;
else
if(c >= 2001 && c <= 5000)
dis = c * 25/100;
else
if(c >= 5001 && c <= 10000)
dis = c * 35/100;
else
dis = c*50/100;

double amt = c - dis;


System.out.println("Amount payable is " + amt);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


9 Board Papers Solution (Section B)

Q-6 class January


{
public static void main(String [] args)
{
String s = "January 26 is celebrated as Republic Day of India";
int l = s.length(), i;
String ns = "";
for(i = 0 ; i < l; i++)
{
char ch = s.charAt(i);
if(Character.isWhitespace(ch) || i == l-1)
{
if(i == l-1)
ns = ns + ch;
if(ns.equalsIgnoreCase("January"))
System.out.print("August ");
else
if(ns.equalsIgnoreCase("26"))
System.out.print("15 ");
else
if(ns.equalsIgnoreCase("Republic"))
System.out.print("Independence ");
else
System.out.print(ns + " ");

ns = "";
}
else
ns = ns + ch;
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


10 Board Papers Solution (Section B)

Q-7 import java.io.*;


class Menu
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter no : ");
String v1 = in.readLine();
int n = Integer.parseInt(v1);
System.out.println("Menu");
System.out.println("1. Natural Logarithm ");
System.out.println("2. Absolute value");
System.out.println("3. Square root ");
System.out.println("4. Random no");
System.out.print("Enter choice : ");
String v2 = in.readLine();
int ch = Integer.parseInt(v2);
switch(ch)
{
case 1:
System.out.println(Math.log(n));
break;
case 2:
System.out.println(Math.abs(n));
break;
case 3:
System.out.println(Math.sqrt(n));
break;
case 4:
System.out.println(Math.random());
break;
default:
System.out.println("Invalid");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


11 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Student
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
int i, hm = 0, sum = 0;
String hn = "";
for(i = 1; i<= 50; i++)
{
System.out.print("Enter name : ");
String name = in.readLine();
System.out.print("Enter marks : ");
String v1 = in.readLine();
int m = Integer.parseInt(v1);
if(m > hm)
{
hm = m;
hn = name;
}
sum = sum + m;
}
double avg = sum/50.0;
System.out.println("Average marks " + avg);
System.out.println("Name = " + hn);
System.out.println("Highest marks = " + hm);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


12 Board Papers Solution (Section B)

Q-9 import java.io.*;


class Selection
{
public static void main(String [] args) throws IOException
{
int x[] = new int[15];
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
int i, j, small,pos;
for(i = 0; i < 15; i++)
{
System.out.print("Enter no : ");
String v1 = in.readLine();
x[i] = Integer.parseInt(v1);
}
for(i = 0; i < 14 ; i++) // sorting the array elements
{
small = x[i];
pos = i;
for(j = i + 1; j <= 14 ; j++)
{
if(x[j] < small)
{
small = x[j];
pos = j;
}
}
t = x[i];
x[i] = x[pos];
x[pos] = t;
}
for(i = 0; i < 15; i++)
{
System.out.println(x[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


13 Board Papers Solution (Section B)

Board Paper 2007


Q-4 import java.io.*;
class Salary
{
String name , addr, subsp;
double msal, tax;
long phone;
void input()throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter name, address , subsp, phone no. and monthly salary : ");
name = in.readLine();
addr = in.readLine();
subsp = in.readLine();
phone = Long.parseLong(in.readLine());
msal = Double.parseDouble(in.readLine());
}
void display()
{
System.out.println("Name is " + name); // display all the details
System.out.println("Address " + addr);
System.out.println("Tax is " + tax);
}
void calculate()
{
double asal = msal * 12;
if(asal > 175000)
tax = (asal-175000) * 5/100;
else
tax = 0;
}
public static void main(String [] args) throws IOException
{
Salary obj = new Salary();
obj.input();
obj.calculate();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


14 Board Papers Solution (Section B)

Q-5 import java.io.*;


class Series
{
public static void main(String [] args) throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter value of n : ");
String v1=in.readLine();
int n=Integer.parseInt(v1);
int i, s= 1, p = 1;
double sum=0;
for(i=2;i<=n;i++)
{
s = s + i;
p = p * i;
sum = sum + (double)s/p;
}
System.out.println("Sum of series = " +sum);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


15 Board Papers Solution (Section B)

Q-6 class MinMax


{
public static void main(String [] args)
{
int x[] = {2,5,4,1,3};
int i, max = x[0] , min = x[0], sum = 0;
for(i = 0; i < 5; i++)
{
if(x[i] > max)
max = x[i];
if(x[i] < min)
min = x[i];
sum = sum + x[i];
}
System.out.println("Minimum value is " + min);
System.out.println("Maximum value is " + max);
System.out.println("Sum is " + sum);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


16 Board Papers Solution (Section B)

Q-7 import java.io.*;


class FrequencyWord
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter string (more than one words) : ");
String s = in.readLine();
System.out.print("Enter word : ");
String w = in.readLine();
int l = s.length();
String ns = "";
int i, f = 0;
for(i = 0 ; i < l; i++)
{
char ch = s.charAt(i);
if(Character.isWhitespace(ch) || i == l-1)
{
if(i == l-1)
{
ns = ns + ch;
}
if(ns.equalsIgnoreCase(w))
f++;
ns = "";
}
else
ns = ns + ch;
}
System.out.println("Frequency of " + w + " is " + f);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


17 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Temperature
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("MENU ");
System.out.println("1. Convert celsius to fahrenheit ");
System.out.println("2. Convert fahrenheit to celsius ");
System.out.print("Enter choice : ");
String v1 = in.readLine();
int op = Integer.parseInt(v1);
switch(op)
{
case 1:
System.out.print("Enter temperature in celsius : ");
String v2 = in.readLine();
double cel = Double.parseDouble(v2);
double f = 1.8 * (cel + 32);
System.out.println("Temperature in fahrenheit is " + f);
break;
case 2:
System.out.print("Enter temperature in fahrenheit : ");
String v3 = in.readLine();
double feh = Double.parseDouble(v3);
double celsius = 5/9.0 * (feh - 32);
System.out.println("Temperature in celsius is " + celsius);
break;
default:
System.out.println("Invalid choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


18 Board Papers Solution (Section B)

Q-9 import java.io.*;


class STRING
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter string : ");
String str = in.readLine();
palin(str);
}
public static void palin(String s)
{
int l = s.length();
int i;
String rev ="";
for(i = l-1; i >= 0; i--)
{
rev = rev + s.charAt(i);
}
if(s.equals(rev))
System.out.println("Palindrome string ");
else
System.out.println("Not a Palindrome string ");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


19 Board Papers Solution (Section B)

Board Paper 2008


Q-4 import java.io.*;
class Employee
{
int pan;
String name;
double taxincome; // TAXABLE INCOME
double tax;
void input() throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter pan number, name and taxable income : ");
pan = Integer.parseInt(in.readLine());
name = in.readLine();
taxincome = Double.parseDouble(in.readLine());
}
void calc()
{
if(taxincome <= 100000)
tax = 0;
else
if(taxincome <= 150000)
tax = (taxincome - 100000)*10/100;
else
if(taxincome <= 250000)
tax = 5000 + (taxincome - 150000) * 20/100;
else
tax = 25000 + (taxincome - 250000) * 30/100;
}
void display()
{
System.out.println("Pan number \t Name \t Tax Income \t Tax");
System.out.println(pan + "\t\t" + name + "\t" + taxincome + "\t" + tax);
}
public static void main(String [] args) throws IOException
{
Employee obj = new Employee();
obj.input();
obj.calc();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


20 Board Papers Solution (Section B)

Q-5 import java.io.*;


class Toggle
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter string : ");
String s = in.readLine();
int l = s.length();
int i;
for(i = 0; i < l ; i++)
{
char ch = s.charAt(i);
if(Character.isUpperCase(ch))
System.out.print(Character.toLowerCase(ch));
else
if(Character.isLowerCase(ch))
System.out.print(Character.toUpperCase(ch));
else
System.out.print(ch);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


21 Board Papers Solution (Section B)

Q-6 class Sorting


{
public static void main(String [] args)
{
String s[] = {"Delhi","Bangalore","Agra","Mumbai","Calcutta"};
int i, j;
String t;
for(i = 0; i < 4; i++)
{
for(j = 0 ; j < 4-i; j++)
{
if(s[j].compareTo(s[j+1]) > 0)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
for(i = 0; i < 5; i++)
{
System.out.println(s[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


22 Board Papers Solution (Section B)

Q-7 import java.io.*;


class Menu
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter number : ");
String v1 = in.readLine();
int x = Integer.parseInt(v1);
System.out.println("MENU");
System.out.println("a. Check Palindrome");
System.out.println("b. Check Perfect");
System.out.print("Enter Choice : ");
char ch = (char)in.read();
switch(ch)
{
case 'a':
int rev = 0,rem, y = x;
while(x!=0)
{
rem = x % 10;
rev = rev * 10 + rem;
x = x/10;
}
if(rev == y)
System.out.println(y +" is Palindrome");
else
System.out.println(y +" is not Palindrome");
break;
case 'b':
int sum = 0,i;
for(i = 1 ; i < x; i++)
{
if(x % i == 0)
sum = sum + i;
}
if(x == sum)
System.out.println(x + " is a perfect number");
else
System.out.println(x + " is not a perfect number");
break;
default:
System.out.println("Invalid Choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


23 Board Papers Solution (Section B)

Q-8 class Volume


{
void vol(int s)
{
System.out.println("Volume of a cube is " + Math.pow(s,3));
}
void vol(double r)
{
System.out.println("Volume of a sphere is " + (4/3.0 * Math.PI *
Math.pow(r,3)));
}
void vol(int l, int b, int h)
{
System.out.println("Volume of a cuboid is " + (l*b*h));
}
public static void main(String [] args)
{
Volume obj = new Volume();
obj.vol(5);
obj.vol(5.6);
obj.vol(5,6,7);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


24 Board Papers Solution (Section B)

Q-9 import java.io.*;


class Series1
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("MENU");
System.out.println("1. Series 1");
System.out.println("2. Series 2");
System.out.print("Enter Choice : ");
int ch = Integer.parseInt(in.readLine());
switch(ch)
{
case 1:
int sum = 0;
for(int i = 2; i <= 20; i+=2)
{
if(i % 4 == 0)
sum = sum - i;
else
sum = sum + i;
}
System.out.println("Sum of series is " + sum);
break;
case 2:
System.out.print("Enter value of x : " );
int x = Integer.parseInt(in.readLine());
double summ = 0;
for(int i = 2 ; i <= 20 ; i+=3)
{
summ = summ + (double)x/i;
}
System.out.println("Sum of series is " + summ);
break;
default:
System.out.println("Invalid Choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


25 Board Papers Solution (Section B)

Board Paper 2009


Q-4 import java.io.*;
class Computer
{
public static void main(String [] args) throws IOException
{
InputStreamReader r 0 new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter customer name : ");
String name = in.readLine();
System.out.print("Enter Purchase Amount : ");
String v1 = in.readLine();
double amount = Double.parseDouble(v1);
System.out.print("Enter L for Laptop and D for Desktop : ");
char type = (char)in.read();
double dis = 0.0;
switch(type)
{
case 'L':
if(amount <= 25000)
dis = 0;
else
if(amount <= 57000)
dis = amount * 5/100;
else
if(amount <= 100000)
dis = amount * 7.5/100;
else
dis = amount * 10/100;
System.out.println("Net amount payable by " + name + " is " + (amount - dis));
break;
case 'D':
if(amount <= 25000)
dis = amount * 5/100;
else
if(amount <= 57000)
dis = amount * 7.5/100;
else
if(amount <= 100000)
dis = amount * 10/100;
else
dis = amount * 15/100;
System.out.println("Net amount payable by " + name + " is " + (amount - dis));
break;
default :
System.out.println("Invalid Purchase ");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


26 Board Papers Solution (Section B)

Q-5 import java.io.*;


class MenuTriangle
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("Menu");
System.out.println("1. Triangle");
System.out.print("2. Inverted Triangle: ");
System.out.print("Enter choice : ");
String v1 = in.readLine();
int ch = Integer.parseInt(v1);
int n,i, j;
switch(ch)
{
case 1:
System.out.print("Enter value of n : ");
String v2 = in.readLine();
n = Integer.parseInt(v2);
for(i = 1; i <= n; i++)
{
for(j = 1; j <= i ; j++)
{
System.out.print(i);
}
System.out.println();
}
break;
case 2:
System.out.print("Enter value of n : ");
String v3 = in.readLine();
n = Integer.parseInt(v3);

for(i = n; i >= 1 ; i--)


{
for(j = 1; j <= i ; j++)
{
System.out.print(i);
}
System.out.println();
}
break;
default:
System.out.println("Invalid choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


27 Board Papers Solution (Section B)

Q-6 import java.io.*;


class Longest
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter string (more than one words) : ");
String s = in.readLine();
int l = s.length();
int i;
String ns = "", ls = "";
for(i = 0 ; i < l; i++)
{
char ch = s.charAt(i);
if(Character.isWhitespace(ch) || i == l-1)
{
if(i == l-1)
ns = ns + ch;
if(ns.length() > ls.length())
ls = ns;
ns = "";
}
else
ns = ns + ch;
}
System.out.println("Longest word " + ls.length());
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


28 Board Papers Solution (Section B)

Q-7 class Overload


{
void num_calc(int num, char ch)
{
if(ch == 's')
System.out.println(Math.pow(num,2));
else
System.out.println(Math.pow(num,3));
}
void num_calc(int a, int b, char ch)
{
if(ch == 'p')
System.out.println(a*b);
else
System.out.println((a+b));
}
void num_calc(String s1, String s2)
{
if(s1.equals(s2))
System.out.println("Equal");
else
System.out.println("Not Equal");
}
public static void main(String [] args)
{
Overload obj = new Overload();
obj.num_calc(2,'s');
obj.num_calc(2,3,'p');
obj.num_calc("hi","he");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


29 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Menu
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("Menu");
System.out.println("1. Buzz no \n 2. GCD ");
System.out.print("Enter choice : ");
String v1 = in.readLine();
int ch = Integer.parseInt(v1);
switch(ch)
{
case 1:
System.out.print("Enter number : ");
String v2 = in.readLine();
int x = Integer.parseInt(v2);
if(x % 7 == 0 || x % 10 == 7)
System.out.println("It is Buzz no");
else
System.out.println("It is not Buzz no");
break;
case 2:
System.out.print("Enter two numbers : ");
String v3 = in.readLine();
int a = Integer.parseInt(v3);
String v4 = in.readLine();
int b = Integer.parseInt(v4);
int big = (a > b) ? a : b;
int small = (a < b) ?a : b;
int rem;
while(true)
{
rem = big % small;
if(rem == 0)
break;
else
{
big = small;
small = rem;
}
}
System.out.println("GCD is " + small);
break;
default:
System.out.println("Invalid choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


30 Board Papers Solution (Section B)

Q-9 import java.io.*;


class Student
{
public static void main(String [] args)throws IOException
{
int roll[] = new int[50];
int s1[] = new int [50];
int s2[] = new int [50];
int s3[] = new int [50];
double avg[] = new double [50];
int i;
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
for(i = 0; i < 50; i++)
{
System.out.print("Enter roll no :");
String v1 = in.readLine();
roll[i] = Integer.parseInt(v1);
System.out.print("Enter marks in 3 subjects :");
String v2 = in.readLine();
s1[i] = Integer.parseInt(v2);
String v3 = in.readLine();
s2[i] = Integer.parseInt(v3);
String v4 = in.readLine();
s3[i] = Integer.parseInt(v4);
avg[i] = (s1[i] + s2[i] + s3[i])/3.0;
}
System.out.println("Roll no \t Average");
for(i = 0; i < 50; i++)
{
System.out.println(roll[i] + "\t" + avg[i]);
}
System.out.println("Roll no \t Average above 80");
for(i = 0; i < 50; i++)
{
if(avg[i] > 80)
System.out.println(roll[i] + "\t" + avg[i]);
}
System.out.println("Roll no \t Average below 40");
for(i = 0; i < 50; i++)
{
if(avg[i] < 40)
System.out.println(roll[i] + "\t" + avg[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


31 Board Papers Solution (Section B)

Board Paper 2010


Q-4 import java.io.*;
class BinarySearch
{
public static void main(String [] args)throws IOException
{
int x[] = {5,7,9,11,15,20,30,45,89,97};
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter no to be searched : ");
String v1 = in.readLine();
int value = Integer.parseInt(v1);
int l = x.length;//to find array length
int lb = 0, ub = l-1, pos = -1, mid;

while(lb <= ub)


{
mid = (lb+ub)/2;
if(value == x[mid])
{
pos = mid;
break;
}
else
if(value < x[mid])
ub = mid-1;
else
lb = mid + 1;
}
if(pos != -1)
System.out.println("Number found at position " + pos);
else
System.out.println("Number not found");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


32 Board Papers Solution (Section B)

Q-5 import java.io.*;


class Student
{
String name;
int age, m1, m2, m3 ,max;
double avg;
public Student(String n, int a, int x, int y, int z)
{
name = n;
age = a;
m1 = x;
m2 = y;
m3 = z;
}
void accept() throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter name : ");
name = in.readLine();
System.out.print("Enter age : ");
age = Integer.parseInt(in.readLine());
System.out.print("Enter marks in 3 subjects : ");
m1 = Integer.parseInt(in.readLine());
m2 = Integer.parseInt(in.readLine());
m3 = Integer.parseInt(in.readLine());
}
void calc()
{
max = (m1 > m2 && m1 > m3) ? m1 : (m2 > m1 && m2 > m3) ? m2 : m3;
avg = (m1+m2+m3)/3.0;
}
void display()
{
System.out.println("Name is " + name);
System.out.println("Age is " + age);
System.out.println("Maximum is " + max);
System.out.println("Average is " + avg);
}
public static void main(String [] args)throws IOException
{
Student obj = new Student("Parshva",10,77,88,99);
obj.accept();
obj.calc();
obj.display();
}
}
Megna’s Institute of Computer Education Megna Doshi : 99251 26432
33 Board Papers Solution (Section B)

Q-6 import java.io.*;


class Shasha
{
public static void main(String [] args)throws IOException
{
String name[] = new String[15];
int charges[] = new int[15];
double dis[] = new double[15];
double amt[] = new double[15];
int i;
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
for(i = 0; i < 15; i++)
{
System.out.print("Enter name : ");
name[i] = in.readLine();
System.out.print("Enter ticket charges : ");
charges[i] = Integer.parseInt(in.readLine());
if(charges[i] > 70000)
dis[i] = charges[i] * 18.0/100;
else
if(charges[i] > 55000)
dis[i] = charges[i] * 16.0/100;
else
if(charges[i] > 35000)
dis[i] = charges[i] * 12.0/100;
else
if(charges[i] > 25000)
dis[i] = charges[i] * 10.0/100;
else
dis[i] = charges[i] * 2.0/100;

amt[i] = charges[i] - dis[i];


}
System.out.println("SL.NO \t NAME \t TICKET CHARGES \t DISCOUNT \t NET AMOUNT");
for(i = 0; i < 15; i++)
{
System.out.println((i+1) + "\t" + name[i] + "\t" + charges[i] + "\t" + dis[i] + "\t" + amt[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


34 Board Papers Solution (Section B)

Q-7 import java.io.*;


class Menu
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("MENU");
System.out.println("a. Check Prime");
System.out.println("b. Check Automorphic");
System.out.print("Enter Choice");
char ch = (char)in.read();
System.out.print("Enter number : ");
String v1 = in.readLine();
int n = Integer.parseInt(v1);
switch(ch)
{
case 'a':
int i;
for(i=2;i<n;i++)
{
if(n%i == 0)
{
System.out.println("Composite");
break;
}
}
if(n == i)
System.out.println("Prime");
break;
case 'b':
int cnt = 0;
int sq = n * n;
while(n!=0)
{
n= n/10;
cnt++;
}
int d = (int) Math.pow(10,cnt);
if(sq%d == 0)
System.out.println("Automorphic");
else
System.out.println("Not a Automorphic");
break;
default:
System.out.println("Invalid Choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


35 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Merge
{
public static void main(String [] args)throws IOException
{
int p[] = new int[6];
int q[] = new int[4];
int r[] = new int[10];
int i;
InputStreamReader r1 = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r1);
for(i = 0; i < 6; i++)
{
System.out.print("Enter number : ");
p[i] = Integer.parseInt(in.readLine());
}
for(i = 0; i < 4; i++)
{
System.out.print("Enter number : ");
q[i] = Integer.parseInt(in.readLine());
}
int k = 0;
for(i = 0; i < 6; i++)
{
r[k++] = p[i];
}
for(i = 0; i < 4; i++)
{
r[k++] = q[i];
}
for(i = 0 ; i< 10; i++)
{
System.out.println(r[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


36 Board Papers Solution (Section B)

Q-9 import java.io.*;


class FrequencyAlphabet
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter string : ");
String s = in.readLine();
s = s.toUpperCase();
int l = s.length();
int i, cnt ;
char j;
System.out.print("Character Frequency ");

for(j = 'A'; j <= 'Z'; j++)


{
cnt = 0;
for(i=0; i < l; i++)
{
char ch = s.charAt(i);
if(ch == j)
cnt++;
}
if(cnt != 0)
System.out.println(j + " \t " + cnt );
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


37 Board Papers Solution (Section B)

Board Paper 2011


Q-4 import java.io.*;
class Mobike
{
int bno,phno,days,charge;
String name;
void input()throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Please enter the bike's number:");
String v1=in.readLine();
bno=Integer.parseInt(v1);
System.out.println("Please enter the phone number of the number:");
String v2=in.readLine();
phno=Integer.parseInt(v2);
System.out.println("Please enter the name of the customer:");
name=in.readLine();
}

void compute()
{
if(days<=5)
charge=days*500;
else if(days<=10)
charge=(5*500)+(days-5)*400;
else
charge=(5*500)+(5*400)+(days-10)*200;
}

void display()
{
System.out.println("Bike No. \t Phone No. \t Name \t No.of days \t Charge");
System.out.println(bno +"\t"+phno+"\t"+name+"\t"+days+"\t"+charge);
}

public static void main(String args[])throws IOException


{
Mobike obj=new Mobike();
obj.input();
obj.compute();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


38 Board Papers Solution (Section B)

Q-5 import java.io.*;


class WeightSelectionSort
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);

int x[] = new int[10];


int i,j,t;
for(i= 0 ;i < 10; i++)
{
System.out.print("Enter Weight : ");
String v1 = in.readLine();
x[i] = Integer.parseInt(v1);
}
int small,pos;
for(i = 0; i < 9 ; i++)
{
small = x[i];
pos = i;
for(j = i + 1; j < 10 ; j++)
{
if(x[j] > small)
{
small = x[j];
pos = j;
}
}
t = x[i];
x[i] = x[pos];
x[pos] = t;
}
for(i = 0; i < 10; i++)
{
System.out.println(x[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


39 Board Papers Solution (Section B)

Q-6 import java.io.*;


class SpecialNo
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter any number : ");
String v1 = in.readLine();
int x = Integer.parseInt(v1);
int rem,sum = 0, y = x, fact, i;
while(x != 0)
{
rem = x%10;
fact = 1;
for(i = rem ; i >= 1; i--)
{
fact = fact * i;
}
sum = sum + fact;
x = x/10;
}
if(y == sum)
System.out.println(y + " is a special number");
else
System.out.println(y + " is not a special number");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


40 Board Papers Solution (Section B)

Q-7 import java.io.*;


class VowelReplace
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter string : ");
String s = in.readLine();
s=s.toLowerCase();
int l = s.length();
int i;
for(i = 0; i < l; i++)
{
char ch = s.charAt(i);
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
System.out.print((char)(ch + 1));
else
System.out.print(ch);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


41 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Overload
{
void compare(int a,int b)
{
int big;

if(a>b)
big=a;
else
big=b;

System.out.println("The Greatest of the two integers is:"+big);


}

void compare(char a,char b)


{
char val;
if(a>b)
val= a;
else
val= b;
System.out.println("The Character with Highest Value is:"+val);
}

void compare(String s1, String s2)


{
if(s1.length() > s2.length())
System.out.println("The Longest String is:"+s1);
else
System.out.println("The Longest String is:"+s2);
}
public static void main(String args[]) throws IOException
{
Overload o1= new Overload();
o1.compare(10,20);
o1.compare('a','c');
o1.compare("sanchi","megna");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


42 Board Papers Solution (Section B)

Q-9 import java.io.*;


class Switchcase
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("1. To print the series");
System.out.println("2. To print the sum of the series");
System.out.println("Enter your choice");
String v1=in.readLine();
int ch=Integer.parseInt(v1);
switch(ch)
{
case 1:
System.out.print("Enter value of n : ");
String v2=in.readLine();
int n=Integer.parseInt(v2);
int i;
for(i=1;i<=n;i++)
{
System.out.print((i*i)-1 + "\t");
}
break;
case 2:
int j;
double sum1=0;
for(j=1; j<=19; j+=2)
{
sum1 = sum1+ (double)j/(j+1);
}
System.out.println("Sum of Series is:" + sum1);
break;
default:
System.out.println("Invalid choice.please enter 1 or 2");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


43 Board Papers Solution (Section B)

Board Paper 2012


Q-4 import java.io.*;
class Library
{
int acc_num;
String title, author;
void input()throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Please enter the accession number of the book:");
String v1=in.readLine();
acc_num =Integer.parseInt(v1);
System.out.print("Please enter the title of the book:");
title=in.readLine();
System.out.print("Please enter the author of the book:");
author=in.readLine();
}
void compute()throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Please enter the number of days late the book is returned:");
String v1=in.readLine();
int days=Integer.parseInt(v1);
double fine=2*days;
System.out.println("Fine is "+fine);
}
void display()
{
System.out.println("ACCESSION NUMBER \t TITLE \t AUTHOR");
System.out.println(acc_num +"\t"+title+"\t"+ author);
}
public static void main(String args[])throws IOException
{
Library obj=new Library();
obj.input();
obj.compute();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


44 Board Papers Solution (Section B)

Q-5 import java.io.*;


class IncomeTax
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Please Enter the age:");
String v1=in.readLine();
int age=Integer.parseInt(v1);
System.out.println("Please enter the gender-male/female:");
String gen=in.readLine();
System.out.println("Please enter the income:");
String v2=in.readLine();
double inc=Double.parseDouble(v2);
double tax=0;
if(age>65 || gen.equalsIgnoreCase("female"))
{
System.out.println("WRONG CATEGORY");
}
else if(age<=65 && gen.equalsIgnoreCase("male"))
{
if(inc<=160000)
tax=0;
else
if(inc>160000 && inc<=500000)
tax=(inc-160000)*0.10;
else
if(inc>500000 && inc<=800000)
tax=((inc-500000)*0.20)+34000;
else
tax=((inc-800000)*0.30)+94000;
System.out.println("TAX IS:" + tax);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


45 Board Papers Solution (Section B)

Q-6 import java.io.*;


class DoubleSequence
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Please enter a string:");
String s=in.readLine();
s=s.toUpperCase();
int l=s.length();
int cnt=0;

for(int i=0;i<l-1;i++)
{
char c = s.charAt(i);
char d = s.charAt(i+1);
if(c==d)
cnt++;
}
System.out.println("Number of double letter sequences:"+cnt);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


46 Board Papers Solution (Section B)

Q-7 import java.io.*;


class Overload
{
void polygon(int n,char ch)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
System.out.print(ch);
}
System.out.println();
}
}
void polygon(int x,int y)
{
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
System.out.print("@");
}
System.out.println();
}
}
void polygon()
{
for(int i=1;i<=3;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
public static void main(String [] args)
{
Overload ob=new Overload();
ob.polygon(2,'O');
ob.polygon(3,5);
ob.polygon();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


47 Board Papers Solution (Section B)

Q-8 import java.io.*;


class MenuDriven
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("1. Generate first 10 terms fibonacci series");
System.out.println("2. Sum of digits");
System.out.println("Enter your choice");
String v1=in.readLine();
int ch=Integer.parseInt(v1);
switch(ch)
{
case 1:
int last=0,prev=1,curr,cnt=3;
System.out.print(last+"\t"+prev);
while(cnt<=10)
{
curr=last+prev;
System.out.print("\t"+curr);
last=prev;
prev=curr;
cnt++;
}
break;
case 2:
System.out.println("Enter a Number");
String v2=in.readLine();
int x=Integer.parseInt(v2);
int rem,sum=0;
while(x!=0)
{
rem=x%10;
sum=sum+rem;
x=x/10;
}
System.out.println("Sum of digits is: "+sum);
break;
default:
System.out.println("Invalid choice..Please enter 1 or 2");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


48 Board Papers Solution (Section B)

Q-9 import java.io.*;


class SearchCity
{
public static void main(String [] args)throws IOException
{
String city[]=new String[10];
int std[]=new int[10];
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
int i;
for(i=0;i<10;i++)
{
System.out.println("Enter city and STD code");
city[i] = in.readLine();
String v2 = in.readLine();
std[i]=Integer.parseInt(v2);
}
System.out.println("Enter the city whose std code you want");
String value=in.readLine();
int flag =0;
for(i=0;i<10;i++)
{
if(value.equalsIgnoreCase(city[i]))
{
System.out.println("SEARCH SUCCESSFUL");
System.out.println("CITY="+city[i]+"\tSTD="+std[i]);
flag = 1;
break;
}
}
if(flag == 0)
{
System.out.println("SEARCH UNSUCCESSFUL,NO SUCH CITY IN THE LIST");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


49 Board Papers Solution (Section B)

Board Paper 2013


Q-4 import java.io.*;
class FruitJuice
{
int product_code,pack_size,product_price;
String flavour,pack_type;
public FruitJuice()
{
product_code=0;
pack_size=0;
product_price=0;
flavour="";
pack_type="";
}
void input()throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Enter the product code number:");
String v1=in.readLine();
product_code=Integer.parseInt(v1);
System.out.println("Enter the flavour of the juice:");
flavour=in.readLine();
System.out.println("Enter the type of packaging:");
pack_type=in.readLine();
System.out.println("Enter the package size:");
String v2=in.readLine();
pack_size=Integer.parseInt(v2);
System.out.println("Enter the product price:");
String v3=in.readLine();
product_price=Double.parseDouble(v3);
}
void discount()
{
product_price =product_price-10;
}
void display()
{
System.out.println("product code number:"+product_code);
System.out.println("flavour of the juice:"+flavour);
System.out.println("type of packaging:"+pack_type);
System.out.println("package size:"+pack_size);
System.out.println("product price:"+product_price);
}
public static void main(String [] args)throws IOException
{
FruitJuice obj=new FruitJuice();
obj.input();
obj.discount();
obj.display();
}
}
Megna’s Institute of Computer Education Megna Doshi : 99251 26432
50 Board Papers Solution (Section B)

Q-5 import java.io.*;


class IBSN
{
public static void main(String args[])throws IOException
{
InputStreamReader r= new InputStreamReader(System.in);
BufferedReader in= new BufferedReader(r);
System.out.println("Enter a ISBN code");
String v1= in.readLine();
int x= Integer.parseInt(v1);
int rem, cnt=0, y = x;
while(x!=0)
{
rem=x%10;
cnt++;
x=x/10;
}
if(cnt!=10)
System.out.println("Illegal ISBN code. ISBN code must be 10 digits");
else
{
int i, sum = 0;
for(i=10;i>=1;i--)
{
rem = y%10;
sum = sum + rem * i;
y = y/10;
}
if(sum%11==0)
System.out.println("Legal ISBN code");
else
System.out.println("Illegal ISBN code");
}
}
}
Megna’s Institute of Computer Education Megna Doshi : 99251 26432
51 Board Papers Solution (Section B)

Q-6 import java.io.*;


class PigLatin
{
public static void main(String[]args)throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Enter string : ");
String s = in.readLine();
int i, l = s.length();
s = s.toUpperCase();
for(i = 0; i < l; i++)
{
char ch = s.charAt(i);
if(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
break;
}
String s1 = s.substring(i);
String s2 = s.substring(0,i);
System.out.println(s1+s2+"AY");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


52 Board Papers Solution (Section B)

Q-7 import java.io.*;


class BubbleSort
{
public static void main(String [] args)throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
int x[]=new int[10];
int i,j,t;
for(i= 0 ;i < 10; i++)
{
System.out.print("Enter number : ");
String v1 = br.readLine();
x[i] = Integer.parseInt(v1);
}
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9-i ; j++)
{
if(x[j] < x[j+1])
{
t = x[j];
x[j] = x[j+1];
x[j+1] = t;
}
}
}
for(i = 0; i < 10; i++)
{
System.out.println(x[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


53 Board Papers Solution (Section B)

Q-8 class Overload


{
double series(double n)
{
int i;
double sum=0.0;
for(i=1;i<=n;i++)
{
sum = sum+1.0/i;
}
return sum;
}

double series(double a, double n)


{
int i,cnt =1;
double sum=0.0;
for(i=1;cnt<=n;i+=3)
{
sum=sum+ i/Math.pow(a,(i+1));
cnt++;
}
return sum;
}
public static void main(String [] args)
{
Overload obj = new Overload();
double ans1 = obj.series(3.0);
System.out.println("Sum of series 1 = " + ans1);
double ans2 = obj.series(3.0,2.0);
System.out.println("Sum of series 2 = " + ans2);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


54 Board Papers Solution (Section B)

Q-9 import java.io.*;


class MenuDriven
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("MENU");
System.out.println("1. To check number is composite or not ");
System.out.println("2. To find the smallest digit in an number ");
System.out.print("Enter choice : ");
String v1 = in.readLine();
int ch = Integer.parseInt(v1);
System.out.print("Enter number : ");
String v2 = in.readLine();
int x = Integer.parseInt(v2);
switch(ch)
{
case 1:
int i;
for(i = 2; i < x; i++)
{
if(x % i == 0)
{
System.out.println(x + " is composite");
break;
}
}
if(x == i)
System.out.println(x + " is not a composite number");
break;
case 2:
int rem, small = 9;
while(x!=0)
{
rem = x%10;
if(rem < small)
small = rem;
x=x/10;
}
System.out.println("Smallest of digit is " + small);
break;
default:
System.out.println("Invalid choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


55 Board Papers Solution (Section B)

Board Paper 2014

Q-4 import java.io.*;


class MovieMagic
{
int year;
String title;
float rating;
public MovieMagic()
{
year=0;
title="";
rating=0.0f;
}
void accept()throws IOException
{
InputStreamReader r= new InputStreamReader(System.in);
BufferedReader in= new BufferedReader(r);
System.out.print("Enter the Year Of Release Of a Movie");
String v1= in.readLine();
year= Integer.parseInt(v1);
System.out.print("Enter the Title Of The Movie");
title= in.readLine();
System.out.print("Enter the Popularity Rating Of The Movie");
String v2= in.readLine();
rating= Float.parseFloat(v2);
}
void display()throws IOException
{
System.out.println("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
System.out.println("Super-Hit");
}
public static void main(String args[]) throws IOException
{
MovieMagic obj= new MovieMagic();
obj.accept();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


56 Board Papers Solution (Section B)

Q-5 import java.io.*;


class Special2Digit
{
public static void main(String args[])throws IOException
{
InputStreamReader r= new InputStreamReader(System.in);
BufferedReader in= new BufferedReader(r);
System.out.println("Enter a Number");
String v1=in.readLine();
int x= Integer.parseInt(v1);
int rem, sum=0, pro=1, s=0, y=x;
while(x!=0)
{
rem=x%10;
sum=sum+rem;
pro=pro*rem;
x=x/10;
}
s=sum+pro;
if(y==s)
System.out.println("Its a Special 2-Digit No");
else
System.out.println("Its not a Special 2-Digit No");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


57 Board Papers Solution (Section B)

Q-6 import java.io.*;


class p6
{
public static void main(String args[]) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("Enter a string ");
String s = in.readLine();
int n = s.lastIndexOf('.');
String ex = s.substring(n+1);
s = s.substring(0,n);
n = s.lastIndexOf('\\');
String fn = s.substring(n+1);
s = s.substring(0,n+1);
System.out.println("Output Path: " +s);
System.out.println("Extension: " +ex);
System.out.println("File Name: " +fn);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


58 Board Papers Solution (Section B)

Q-7 class Overload


{
double area(double a, double b, double c)
{
double s = (a+b+c)/2;
double ar = Math.sqrt(s*(s-a)*(s-b)*(s-c));
return ar;
}
double area(int a, int b, int height)
{
double ar=0.5*height*(a+b);
return ar;
}
double area(double diagonal1, double diagonal2)
{
double ar=0.5*(diagonal1*diagonal2);
return ar;
}
public static void main(String args[])
{
Overload o1= new Overload();
System.out.println(o1.area(5,4,8));
System.out.println(o1.area(5.5,4.4,8.8));
System.out.println(o1.area(8.5,9.0));
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


59 Board Papers Solution (Section B)

Q-8 import java.io.*;


class p8
{
public static void main(String args[]) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("1. Term Deposit");
System.out.println("2. Recurring Deposit");
System.out.println("Enter ur choice ");
String v1 = in.readLine();
int ch = Integer.parseInt(v1);
double p , n , r1, A;
switch(ch)
{
case 1:
System.out.println("Enter Principal amount ");
String v2 = in.readLine();
p = Double.parseDouble(v2);
System.out.println("Enter Rate of Intrest");
String v3 = in.readLine();
r1 = Double.parseDouble(v3);
System.out.println("Enter time in years ");
String v4 = in.readLine();
n= Double.parseDouble(v4);
A = p * Math.pow(1.0+(double)r1/100 , n);
System.out.println("Maturity Amount is : " +A);
break;
case 2:
System.out.println("Enter monthly installment ");
String v5 = in.readLine();
p= Double.parseDouble(v5);
System.out.println("Enter Rate of Intrest");
String v6 = in.readLine();
r1= Double.parseDouble(v6);
System.out.println("Enter time in months ");
String v7 = in.readLine();
n= Double.parseDouble(v7);
A= p * n + (p * n*(n+1)/2 *r1/100 *1.0/12);
System.out.println("Maturity Amount is : " +A);
break;
default:
System.out.println("Wrong choice ");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


60 Board Papers Solution (Section B)

Q-9 import java.io.*;


class BinarySearch
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
int x[] = {1982,1987,1993,1996,1999,2003,2006,2007,2009,2010};
int pos = -1;
System.out.print("Enter the year of graduation: ");
String v1 = in.readLine();
int value = Integer.parseInt(v1);
int lb = 0,ub = x.length-1,mid;
while(lb <= ub)
{
mid = (lb+ub)/2;
if(value == x[mid])
{
pos = mid;
break;
}
else
if(value > x[mid])
lb = mid + 1;
else
ub = mid - 1;
}
if(pos != -1)
System.out.println("Record Exists");
else
System.out.println("Record Does Not Exists ");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


61 Board Papers Solution (Section B)

Board Paper 2015

Q-4 import java.io.*;


class ParkingLot
{
int vno, hours;
double bill;
void input()throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter vehicle number : ");
String v1=in.readLine();
vno=Integer.parseInt(v1);
System.out.print("Enter hours : ");
String v2=in.readLine();
hours=Integer.parseInt(v2);
}
void calculate()
{
if(hours<=1)
bill=3;
else
bill=3+(hours-1);* 1.50;
}
void display()
{
System.out.print("Vehicle no. is : "+vno);
System.out.print("Hour is : "+hours);
System.out.print("Your bill is : "+bill);
}
public static void main(String []args)throws IOException
{
ParkingLot obj=new ParkingLot();
obj.input();
obj.calculate();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


62 Board Papers Solution (Section B)

Q-5 class Q5a


{
public static void main(String args[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(j%2==1)
System.out.print("*");
else
System.out.print("#");
}
System.out.println();
}
}
}

class Q5b
{
public static void main(String args[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


63 Board Papers Solution (Section B)

Q-6 import java.io.*;


class Q6
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter Number of Students : ");
String v1=in.readLine();
int n =Integer.parseInt(v1);
int roll[] = new int[n];
String name[] = new String[n];
int m1[] = new int[n];
int m2[] = new int[n];
int m3[] = new int[n];
double avg[] = new double[n];
String remark="";
int i;
for(i=0;i<n;i++)
{
System.out.print("Enter Roll Number of Students : ");
String v2=in.readLine();
roll[i] =Integer.parseInt(v2);
System.out.print("Enter Name of Student : ");
name[i]=in.readLine();
System.out.print("Enter Marks of First Subject : ");
String v3=in.readLine();
m1[i] =Integer.parseInt(v3);
System.out.print("Enter Marks of Second Subject : ");
String v4=in.readLine();
m2[i] =Integer.parseInt(v4);
System.out.print("Enter Marks of Third Subject : ");
String v5=in.readLine();
m3[i]=Integer.parseInt(v5);
avg[i]=(m1[i]+m2[i]+m3[i])/3.0;
if(avg[i]>=85)
remark="EXCELLENT";
else if(avg[i]>=75)
remark="DISTINCTION";
else if(avg[i]>=60)
remark="FIRST CLASS";
else if(avg[i]>=40)
remark="PASS";
else
remark="POOR";
System.out.println(remark);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


64 Board Papers Solution (Section B)

Q-7 import java.io.*;


class Q7
{
void Joystring(String s,char ch1,char ch2)
{
System.out.println(s.replace(ch1,ch2));
}
void Joystring(String s)
{
System.out.println("First index of space is " + s.indexOf(' '));
System.out.println("Last index of space is " + s.lastIndexOf(' '));
}
void Joystring(String s1,String s2)
{
System.out.println(s1.concat(" ").concat(s2));
}
public static void main(String args[])
{
Q7 obj=new Q7();
obj.Joystring("Hello",'e','a');
obj.Joystring("Hello this is java");
obj.Joystring("Hello","java");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


65 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Q8
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
int i,j;
String name[]=new String[20];
String t;
for(i=0;i<20;i++)
{
System.out.print("Enter Name of Student : ");
name[i]=in.readLine();
}
for(i=0;i<19;i++)
{
for(j=0;j<19-i;j++)
{
if(name[j].compareTo(name[j+1])<0)
{
t=name[j];
name[j]=name[j+1];
name[j+1]=t;
}
}
}
for(i=0;i<20;i++)
{
System.out.println(name[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


66 Board Papers Solution (Section B)

Q-9 import java.io.*;


class Q9
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Enter your choice : ");
System.out.println("1: To find the factors of number");
System.out.println("2: To find the factorial of number");
String v1=in.readLine();
int ch=Integer.parseInt(v1);
System.out.print("Enter a number : ");
String v2=in.readLine();
int num=Integer.parseInt(v2);
int i,fact=1;
switch(ch)
{
case 1:
System.out.println("Factors are: ");
for(i=1;i<num;i++)
{
if(num%i==0)
System.out.println(i);
}
break;
case 2:
for(i=num;i>=1;i--)
{
fact=fact*i;
}
System.out.println("Factorial of "+num+" is "+fact);
break;
default:
System.out.println("Wrong choice entered");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


67 Board Papers Solution (Section B)

Board Paper 2016


Q-4 import java.io.*;
class BookFair
{
String Bname;
double price;
public BookFair() //default constructor
{
Bname="";
price=0.0;
}
void input()throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter Bookname");
Bname=in.readLine();
System.out.print("Enter Price");
String v1=in.readLine();
price=Double.parse.Double(v1);
}
void calculate()
{
double discount=0.0;
if(price<=1000)
discount=price*2/100;
else
if(price<=3000)
discount=price*10/100;
else
discount=price*15/100;
price=price-discount;
}
void display()
{
System.out.print("Bookname : "+Bname);
System.out.print("Price after discount : "+price);
}
public static void main(String[]args)throws IOException
{
BookFair obj=new BookFair();
obj.input();
obj.calculate();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


68 Board Papers Solution (Section B)

Q-5 import java.io.*;


class Q5
{
public static void main(String[]args)throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter 1 to print Floyd's traingle ");
System.out.print("Enter 2 to display String pattern");
String v1=in.readLine();
int ch=Integer.parseInt(v1);
switch(ch)
{
case 1:
int i,j,k=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(k++);
}
System.out.println();
}
break;
case 2:
String s="ICSE";
int l=s.length();
for(i=0;i<l;i++)
{
for(j=0;j<=i;j++)
{
System.out.print(s.charAt(j));
}
System.out.println();
}
break;
default:
System.out.println("Wrong choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


69 Board Papers Solution (Section B)

Q-6 import java.io.*;


class Special
{
public static void main(String[]args)throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter String : ");
String s=in.readLine();
String rev="";
int l=s.length();
int i;
char first=s.charAt(0);
char last=s.charAt(l-1);
if(first==last)
{
for(i=l-1;i>=0;i--)
{
char ch=s.charAt(i);
rev=rev+ch;
}
if(s.equals(rev))
System.out.println("Palindrome String");
else
System.out.println("Special String");
}
else
System.out.println("Not Special String");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


70 Board Papers Solution (Section B)

Q-7 class Overload


{
void series(int n,double x)
{
int i;
double s=0.0;
for(i=1;i<=n;i++)
{
if(i%2!=0)
s=s+x/i;
else
s=s-x/i;
}
System.out.println("Sum = "+s);
}
void series()
{
int i,p=1;
double sum=0.0;
for(i=1;i<=20;i++)
{
p=p*i;
sum=sum+p;
}
System.out.println("Sum = " + sum);
}
public static void main(String [] args)
{
Overload obj = new Overload();
obj.series(3,2.0);
obj.series();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


71 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Niven
{
public static void main(String[]args)throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter a number : ");
String v1=in.readLine();
int x=Integer.parseInt(v1);
int sum=0,y=x,rem;
while(x!=0)
{
rem=x%10;
sum=sum+rem;
x=x/10;
}
if(y%sum==0)
System.out.println("Niven number");
else
System.out.println("Not Niven number");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


72 Board Papers Solution (Section B)

Q-9 import java.io.*;


class Wonders
{
public static void main(String[]args)throws IOException
{
String wonder[ ]={"CHICHEN ITZA","CHRIST THE
REDEEMER","TAJMAHAL","GREAT WALL OF
CHINA","MACHU PICCHU","PETRA","COLOSSEUM"};
String country[ ] =
{"MEXICO","BRAZIL","INDIA","CHINA","PERU","JORDAN","ITALY"};
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter a country to be searched : ");
String value=in.readLine();

int i,flag = 0;
for(i=0;i<7;i++)
{
if(value.equalsIgnoreCase(country[i]))
{
System.out.println("Country = " + country[i]);
System.out.println("Wonder = " + wonder[i]);
flag = 1;
break;
}
}
if(flag == 0)
System.out.println("Sorry not found");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


73 Board Papers Solution (Section B)

Board Paper 2017

Q-4 import java.io.*;


class ElectricBill
{
String n;
int units;
double bill;
void accept() throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter name of the customer : ");
n = in.readLine();
System.out.print("Enter number of units : ");
String v1 = in.readLine();
units = Integer.parseInt(v1);
}
void calculate()
{
if(units <= 100)
bill = units * 2;
else
if(units <= 300)
bill = (100 * 2) + (units - 100) *3;
else
bill = (100 * 2) + (200 * 3) + (units - 300) * 5;
if(units > 300) // calculating surcharge for units greater than 300
bill = bill + bill * 2.5/100;
}
void print()
{
System.out.println("Name of the customer " + n);
System.out.println("Number of units consumed " + units);
System.out.println("Bill Amount " + bill);
}
public static void main(String [] args) throws IOException
{
ElectricBill obj = new ElectricBill();
obj.accept();
obj.calculate();
obj.print();
}
}
Megna’s Institute of Computer Education Megna Doshi : 99251 26432
74 Board Papers Solution (Section B)

Q-5 import java.io.*;


class SPYNUmber
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.print("Enter number : ");
String v1 = in.readLine();
int x = Integer.parseInt(v1);
int rem, sum = 0, pro = 1;
while(x!=0)
{
rem = x%10;
sum = sum + rem;
pro = pro * rem;
x = x/10;
}
if(sum == pro)
System.out.println("It is a SPY number");
else
System.out.println("It is not a SPY number");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


75 Board Papers Solution (Section B)

Q-6 import java.io.*;


class MenuSeries
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
System.out.println("MENU");
System.out.println("1. Series 1");
System.out.println("2. Series 2 ");
System.out.println("Enter choice : ");
String v1 = in.readLine();
int ch = Integer.parseInt(v1);
switch(ch)
{
case 1:
int i,x=2;
double sum = 0.0;
for(i = 1; i <= 20; i++)
{
if(i % 2 == 0)
sum = sum - Math.pow(x,i);
else
sum = sum + Math.pow(x,i);
}
System.out.print("Sum of series " + sum);
break;
case 2:
int j,s = 1;
for(j = 1; j <= 5; j++)
{
System.out.print(s + "\t");
s=s*10+1;
}
break;
default:
System.out.println("INVALID CHOICE");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


76 Board Papers Solution (Section B)

Q-7 import java.io.*;


class ARRAY
{
public static void main(String [] args) throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
int x[] = new int[20];
int i;
for(i=0;i<20;i++)
{
System.out.print("Enter number : ");
String v1 = in.readLine();
x[i] = Integer.parseInt(v1);
}
int max =x[0], min = x[0], sum = 0;
for(i=0;i<20;i++)
{
sum = sum + x[i];
if(x[i] > max)
max =x[i];
if(x[i] < min)
min = x[i];
}
System.out.println("Largest number is = "+ max);
System.out.println("Smallest number is = "+ min);
System.out.println("Sum of all the elements is = "+ sum);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


77 Board Papers Solution (Section B)

Q-8 import java.io.*;


class Overload
{
void check(String str,char ch)
{
int i, f = 0;
for(i = 0; i < str.length(); i++)
{
char c = str.charAt(i);
if(ch == c)
f++;
}
System.out.println("Frequency of " + ch + " is " + f);
}
void check(String s1)
{
int i;
for(i = 0; i < s1.length(); i++)
{
char c = s1.charAt(i);
switch(c)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.print(Character.toLowerCase(c) + " ");
}
}
}
public static void main(String args[])
{
Overload obj=new Overload();
obj.check("Success",'s');
obj.check("computer");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


78 Board Papers Solution (Section B)

Q-9 import java.io.*;


class Selection
{
public static void main(String [] args)throws IOException
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(r);
String x[] = new String[40];
int i,j;
for(i= 0 ;i < 40 ; i++) // storing numbers in an array
{
System.out.print("Enter number : ");
x[i] = in.readLine();
}
String small;
int pos;
for(i = 0; i < 39 ; i++) // sorting the array elements
{
small = x[i];
pos = i;
for(j = i + 1; j <= 39 ; j++)
{
if(x[j].compareTo(small) > 0)
{
small = x[j];
pos = j;
}
}
String t = x[i];
x[i] = x[pos];
x[pos] = t;
}
for(i = 0; i < 40; i++) // printing the numbers
{
System.out.println(x[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


79 Board Papers Solution (Section B)

Board Paper 2018

Q4. import java.io.*;


class RailwayTicket
{
String name,coach;
long mobno;
int amt,totalamt;
void accept()throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Ente name: ");
name=in.readLine();
System.out.print("Enter coach(in uppercase): ");
coach=in.readLine();
System.out.print("Enter mobile number: ");
String v1=in.readLine();
mobno=Long.parseLong(v1);
System.out.print("Enter amount: ");
String v2=in.readLine();
amt=Integer.parseInt(v2);
}
void update()
{
if(coach.equals("FIRST AC"))
totalamt=amt+700;
else
if(coach.equals("SECOND AC"))
totalamt=amt+500;
else
if(coach.equals("THIRD AC"))
totalamt=amt+250;
else
if(coach.equals("SLEEPER"))
totalamt=amt+0;
}
void display()
{
System.out.println("NAME: " + name);
Megna’s Institute of Computer Education Megna Doshi : 99251 26432
80 Board Papers Solution (Section B)

System.out.println("COACH: " + coach);


System.out.println("MOBILE NUMBER: " + mobno);
System.out.println("AMOUNT: " + amt);
System.out.println("TOTAL AMOUNT: " + totalamt);
}
public static void main(String args[])throws IOException
{
RailwayTicket obj=new RailwayTicket();
obj.accept();
obj.update();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


81 Board Papers Solution (Section B)

Q5. import java.io.*;


class Pronic
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter number: ");
String v1=in.readLine();
int x=Integer.parseInt(v1);
int i,flag=0;
for(i=0;i<x;i++)
{
if(i*(i+1)==x)
{
flag=1;
break;
}
}
if(flag==1)
System.out.println("It is pronic number");
else
System.out.println("It is not a pronic number");
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


82 Board Papers Solution (Section B)

Q6. import java.io.*;


class Upper
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.print("Enter string: ");
String s=in.readLine();
int l=s.length();
s=s.toLowerCase();
int i;
for(i=0;i<l;i++)
{
char ch=s.charAt(i);
if(i==0)
System.out.print(Character.toUpperCase(s.charAt(0)));
else
if(ch==' ')
{
System.out.print(ch);
System.out.print(Character.toUpperCase(s.charAt(i+1)));
i++;
}
else
System.out.print(ch);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


83 Board Papers Solution (Section B)

Q7. import java.io.*;


class Print
{
double volume(double R)
{
return(4.0/3*Math.PI*Math.pow(R,3));
}
double volume(double H, double R)
{
return(Math.PI*Math.pow(R,2)*H);
}
double volume(double L, double B,double H)
{
return(L*B*H);
}
public static void main(String args[])
{
Print obj=new Print();
System.out.println(obj.volume(5.5));
System.out.println(obj.volume(2.0,1.0));
System.out.println(obj.volume(2.5,3.5,4.5));
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


84 Board Papers Solution (Section B)

Q8. import java.io.*;


class MENU
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("MENU");
System.out.println("1.Pattern 1");
System.out.println("2.PAttern 2");
System.out.println("Enter choice: ");
String v1=in.readLine();
int ch=Integer.parseInt(v1);
switch(ch)
{
case 1:
char i,j;
for(i='E';i>='A';i--)
{
for(j='A';j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
break;
case 2:
String s="BLUE";
int k,l;
for(k=0;k<s.length();k++)
{
for(l=0;l<=k;l++)
{
System.out.print(s.charAt(k));
}
System.out.println();
}
break;
default:
System.out.println("Invalid choice");

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


85 Board Papers Solution (Section B)

}
}
}

Q9. import java.io.*;


class Student
{
public static void main(String args[])throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(r);
System.out.println("Enter value of n: ");
String v1=in.readLine();
int n=Integer.parseInt(v1);
String name[]=new String[n];
int totalmarks[]=new int[n];
int i;
for(i=0;i<n;i++)
{
System.out.print("Enter name: ");
name[i]=in.readLine();
System.out.print("Enter marks: ");
String v2=in.readLine();
totalmarks[i]=Integer.parseInt(v2);
}
int sum=0;
for(i=0;i<n;i++)
{
sum=sum+totalmarks[i];
}
double avg=sum/(double)n;
System.out.println (“Deviation of each students marks “);
for(i=0;i<n;i++)
{
System.out.println(Math.abs(totalmarks[i]-avg));
}
System.out.println("Average= " + avg);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


86 Board Papers Solution (Section B)

Board Paper 2019


Q-4 import java.util.*;
class ShowRoom
{
String name;
long mobno;
double cost,dis,amount;
ShowRoom() //default constructor
{
name="";
mobno=0;
cost=0.0;
dis=0.0;
amount=0.0;
}
void input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");
name=sc.nextLine();
System.out.print("Enter your Mobile Number: ");
mobno=sc.nextLong();
System.out.print("Enter cost of item purchased: ");
cost=sc.nextDouble();
}
void calculate()
{
if(cost<=10000)
dis = cost * 5/100;
else
if(cost>10000 && cost<=20000)
dis = cost * 10/100;
else
if(cost>20000 && cost<=35000)
dis = cost * 15/100;
else
dis = cost * 20/100;
amount = cost - dis;
}
void display()
Megna’s Institute of Computer Education Megna Doshi : 99251 26432
87 Board Papers Solution (Section B)

{
System.out.println("Name of the customer: "+name);
System.out.println("Mobile number : "+mobno);
System.out.println("Amount to be paid after discount: "+amount);
}
public static void main(String [] args)
{
ShowRoom obj = new ShowRoom();
obj.input();
obj.calculate();
obj.display();
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


88 Board Papers Solution (Section B)

Q-5 import java.util.*;


class MenuDriven
{
public static void main(String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Press 1 to See Unicode of A to Z ");
System.out.println("Press 2 for pattern");
System.out.print("Enter Your Choice (1 or 2):");
int choice = sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Letters : Unicode");
int m;
for(m=65;m<=90;m++)
{
System.out.println((char)m+" : "+m);
}
break;
case 2:
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j);
}

System.out.println();
}
break;
default:
System.out.println("Invalid choice");
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


89 Board Papers Solution (Section B)

Q-6 import java.io.*;


class BubbleSort
{
public static void main(String [] args)throws IOException
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
int x[]=new int[15];
int i,j,t;
for(i= 0 ;i < 15; i++)
{
System.out.print("Enter number : ");
String v1 = br.readLine();
x[i] = Integer.parseInt(v1);
}
for(i = 0; i < 14; i++)
{
for(j = 0; j < 14-i ; j++)
{
if(x[j] < x[j+1])
{
t = x[j];
x[j] = x[j+1];
x[j+1] = t;
}
}
}
for(i = 0; i < 15; i++)
{
System.out.println(x[i]);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


90 Board Papers Solution (Section B)

Q-7 class Overload


{
void series(int x,int n)
{
double sum=0.0;
for(int i=1;i<=n;i++)
{
sum= sum + Math.pow(x,i);
}
System.out.println(sum);
}
void series(int p)
{
int sum=0;
for(int i=1;i<=p;i++)
{
sum = sum + i*i*i-1;
}
System.out.println(sum);
}
void series()
{
double sum=0;
for(int i=2;i<= 10;i++)
{
sum = sum + 1.0/i;
}
System.out.println(sum);
}
public static void main(String [] args)
{
Overload obj = new Overload();
obj.series(2,5);
obj.series(10);
obj.series();
}
}

Q-8 import java.util.*;


class CountLetterA

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


91 Board Papers Solution (Section B)

{
public static void main(String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a sentence: ");
String s=sc.nextLine();
s=s.toUpperCase();
int i, cnt=0;

for(i=0;i<s.length();i++)
{
char ch = s.charAt(i);
if(i==0 && ch == 'A')
cnt++;
else
if(Character.isWhitespace(ch) && s.charAt(i+1)=='A')
cnt++;
}
System.out.println("Total number of words Starting with letter 'A'= "+cnt);
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432


92 Board Papers Solution (Section B)

Q-9 class TechNum


{
public static void main(String[]args)
{
int left,right,sum_sqr;
for(int i=1000;i<=9999;i++) //Taking 4 digit numbers only
{
left=i/100;
right=i%100;
sum_sqr=(int)Math.pow((left+right),2);
if(sum_sqr==i)
System.out.println(i);
}
}
}

Megna’s Institute of Computer Education Megna Doshi : 99251 26432

You might also like