ICSE BlueJ Logical Program

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

ICSE BlueJ Logical Program

Logical Questions for Java or BlueJ


Home Page

(Note: All programs codes are Tested in BlueJ


grams which are not solved try it out yourself, because one same pattern questions alread
Questions Based on Logic & Calculation:
& C then calculate this formula.

3 (B + C)1/2

in(String args[])

4;

.pow((a+b),2);
.sqrt(b+c);
t(a+c);

("The answer is : "+r);

ple Interest.

in(String args[])

100;
("Simple intrest = "+si);
rcumference of circle.

in(String args[])

;
;
("Area of the Circle of radious "+r+" is : "+a);
("Circumference : "+c);

angle.

in(String args[])

4;

2.0;
(s-a)*(s-b)*(s-c))/(2*a*b);
("Area of the Triangle");
("of sides "+a+","+b+","+c);
("is : "+area);

porting documentation to enter any three real numbers and calculate X where:
er portion
tion

in(String args[])

2 = 7.19,n3 = 3.65;
3)/(d1+d2+d3);
("The value of X is : "+x);

on:
number is divisible by 5 or not.

in(String args[])

n ("The number "+n+" is divisible by 5");

n ("The number "+n+" is not divisible by 5");

eck whether the number is divisible by both 2 and 3 or not.

in(String args[])

3 = = 0)
n ("The number "+n+" is divisible by 2 and 3");

n ("The number "+n+" is not divisible by 2 and 3");

rams to accept three numbers and find which one is greater (one using if statement and an

in(int a,int b,int c)

(a>c)?a:c) : ((b>c)?b:c);
The Highest Number is : "+max);

nd out the given number is divisible by 5 or not, if not then print the nearest number from

in(int n)

n ("The number "+n+" is divisible by 5");

tln ("The nearest number is "+(n-r+5));

tln ("The nearest number is "+(n-r));

t the basic salary of a person. He get 15% of the basic as HRA, 15% of the basic as Conve
nt allowance. The total salary is calculated by adding Basic + HRA + Conveyance + Enterta
salary of person.

in(int basic)

.15;
basic*.15;
t = basic*.10;
= basic + HRA + conveyance + entertainment;
("Total Salary : "+totalSalary);

ets commission on the following basis:


Commission Rate
3%
0 12%
re 31%
input, calculate and print his commission amount and rate of commission.

in(int sales)

= 0.0;

s*.03;

& sales< = 50000)

s*.12;

s*.31;

("Commission Rate : "+rate+"%");


("Commission Amount : "+commission);

r the three sides of a triangle. Decide whether it is a scalene, isosceles or equilateral triang

in(String args[])

arseInt(args[0]);
arseInt(args[1]);
arseInt(args[2]);
= c && c = = a)
n ("Equileteral Triangle");
b! = c && c! = a)
n ("Scalean Triangle");

n ("Isoceles Triangle");
r books returned late. Following are the fines: first five days 40 paisa per day, Six to ten d
day. Design a program to calculate the fine assuming that a book is returned N days late.

in(int Ndays)

0;

s*.40;
ays< = 10)
s*.65;

s*.80;
("FINE AMOUNT (Rs.) : "+fineAmount);

ent wishes to compute monthly telephone bills for its customers using the following rules. M
e per unit for next 60 units, plus 50 paise per unit for next 60 units, plus 40 paise per unit
ates the monthly bill, with input MESSAGE (the number of message units) and CUSTNO (th
e bill in following format.

in(int messageUnit,int customerNo)

0)

>80 && messageUnit< = 140)


geUnit-80)*0.60;
>140 && messageUnit< = 200)
ssageUnit-140)*0.50;
>200)
(messageUnit-200)*0.40;
("CUSTOMER NUMBER : "+customerNo);
("MESSAGE UNIT : "+messageUnit);
("BILL AMOUNT : "+bill);

he hourly rate (R) for the first 40 hours of work in a week. Thereafter, he is paid at 1.25 ti
t 1.5 times of the hourly rate (R) for the further hours of work in the week. Taking the num
he weekly wages (W) is to be calculated.

in(int H,int R)

= 56)
*1.25;

5+(H-56)*R*1.5;
The Weekly Wages : "+W);

pute BI-monthly telephone charges for subscriber. Use the following information:
: Rs.380
months: 120
ee limits upto 100 calls: Rs.1
ess of 100 calls: Rs. 1.25

in(int calls)

;
ls< = 220)
s-120)*1;

calls-220)*1.25;
("BILL AMOUNT : "+bill);
t the code of a particular item, quantity purchased and rate. Then calculate the purchased
he gifts to the customers are given in the following manner:
Rs.) Gift
A key ring
A leather purse
A pocket calculator

in(int code, int qty, double rate)

rate;
("Purchase Price : "+price);
price< = 500)
n ("Gift item : Key Ring");
ce< = 1000)
n ("Gift item : Leather Purse");

n ("Gift item : Pocket Calculator");

Some Questions on multiple IF condition


the monthly salary from the user, find and display income tax with the help of the following
Income Tax
Nil
20% of Monthly salary
30% of Monthly salary
40% of Monthly salary

mission on the value of his sales as per the following table.


Commission(%)
1
5
10
e and print the commission using sale value as input. The program is to keep on calculating
es value zero is input.
target for each of the four regions (EAST, WEST , NORTH and SOUTH). The company allots

ough command line parameters, the total target amount proposed by the company and pr

he car bill for a particular tourist.


Charge Driver.
Rs.800 Rs.100.
00 Rs.800+Rs10/km Rs 300.
above 100
Rs.15per km Rs 500
Rs.600 Rs 100.
200 Rs.600+Rs.8/km Rs 300
above 100
Rs.12 per km Rs.500

ethod to calculate the salary increment of employees based on their basic pay. Calculate th

-
-
/-

e this keyword, to calculate the prize amount for a cricketer depending upon his text avera
duate Prize Amount
Rs. 1,00,000.00
Rs. 50,000.00
Rs. 25,000.00
Rs. 10,000.00

write a program in java to calculate the grade as per the given criteria:
de
Excellent
First Div.
Second Div.
Third Div.

n values the variable basic salary and calculate the DA and the gross salary and print them

en DA is 5% of basic
0 then DA is 8% of basic
0 then DA is 10% of basic
then DA is 12% of basic
DA.

in an organization. You have to display the number of employees getting Net-Salary above
ollowing the table given below.
Basic_salary) IT (% Gross_Salary)
8% 6%
15% 9%
18% 12%
ess Allowance and income Tax respectively.
lary + DA
ry - IT

traveling allowance for 50 employees of an organization by taking distance traveled as inp


g to the following table.
nt.
00
s 200 + Rs 5 per extra km above 20
Rs 500 + Rs 5 per extra km above 50.
per km.

the following tables:


Commission(% of sale)
Nil
12%
15%
18%
an gets a fixed allowance of Rs 550 and also a bonus of Rs 500 if a salesman achieves the
esman along with the sales. Also display the number of salesman having income of 5000 o

loyees who are divided into four grades as follows:


th) D.A.(% of Basic) H.R.A.(% of Basic)
40% 30%
40% 25%
00 30% 20%
30% 15%
al of Basic, D.A., and H.R.A., is above Rs.50,000 per month then Income Tax at the rate o
ed on monthly basis at source. Taking name of the employees and the Basic(monthly) pay
hly pay, DA, HRA, Monthly Income Tax and Net Monthly Salary, for each employee is to be
.

ith member variables: sales, commission

ept sales value


ulate and return commission amount.
ulated according to the following criteria
commission rate
15%
ut below 5000 10%
ut below 3000 5%
2%

having member variable: calls, charge

to calculate the telephone bill.


n
rding to the following rule-

0
ll
/call

n Rs 50/- will be paid extra by the customer


ill amount
ccept no. of calls and display menu

)
ing to the option entered by the user and then finally display the bill.

late monthly telephone bill for a consumer after accept number of call according to given c
00/-

1.25/call
.50/call

the sales or any 20 sales men. Calculate and print the commission with an added allowanc
ed by using the following table:-
on

accept an amount from the user and hence

the remainder amount.


he remainder amount.
e remainder amount.
he remainder amount.
0 = 5, Remainder = Rs. 42
der = Rs. 42
der = Rs. 2.
der = Rs. 2.

as three data member Name, roll and Marks of 5 Subjects the steam is assigned based on
Stream
ience with computers
cience without Computers
ommerce with Maths
ommerce without Maths
a class student and allot the stream and print them.

e charge for the parking of 2wheeler, 3wheeler and 4wheller (same charges) as per the fo
e

ional 8 hours
each addition 8 hrs.
ed and prints the charges as per given criteria.

Questions Based on Loops or Nested Loops


ural numbers (using for, while and do-while loop).

numbers and the sum of them.

lay the table of given number.

of a country is PO and it increases by 5% every year. The population (P) after n years is gi
m to find the population every year for the next ten years.

series
in(String args[])

7;i++)

(s+" ");

in(String args[])

7;i++)

(s+" ");

in(String args[])

6;i++)
((int) Math.pow(i,2)-1 + " ");

acci series)

in(String args[])
;
+)

(a+" ");

in(String args[])

;
+)

(a+" ");

in(String args[])

5;i++)
((i*2)+" "+(i*3)+" ");
in(String args[])

+)

n (a+" ");
n (b+" ");

in(String args[])

5;i++)

ow(i,3)) - 1;
(n+" ");

ven series
+ 6 - 7 + 8 - 9 + ……………… + Nth

X+3)4+(X+4)5+…………… +(X+N)N+1

+ (1+2+3+4) + ………… + (1+…………+15)

X3 + 4!X4
+ X6

+ 4x5 + ... + 19x20

orial of the first ten natural numbers.

in(String args[])

10;i++)

n ("The factorial of number "+i+" is "+f);

t all the factors of a number.

in(String args[])

arseInt(args[0]);
("The all Factors of given no. "+n+" is");
n;i++)

tln (i);

r and check whether the number is perfect number or not. A number is called perfect num
e number is equal to that number. (For e.g. 6 is a perfect number. Factors are 1, 2 & 3 and
in(String args[])

arseInt(args[0]);

n ("The given no. "+n+" is a Perfect no");

n ("The given no. "+n+" is not a Perfect no");

ect numbers up to 1000.

in(String args[])

("The Perfect nos between 1 to 1000 are ");


;n++)

tln (n);

pt a number, check whether the numbers is prime number or not. If number is prime, the
UMBER".
in(String args[])

arseInt(args[0]);

("The given no. "+n+" is a prime number");

("The given no. "+n+" is not a prime number");

lay all prime numbers between 100 to 200.

in(String args[])

The Prime nos between 100 to 200 are : ");


0;n++)

t (n+" ");
ude oil of a country in millions of barrel may be estimated by the following set of equations
r 0< = t< = 3 and P = 14+(T-5/2)^2, for t>3, Write a program to print the quantity of pr

pt a number then print the sum of digits and number of digits present in it. (E.g. If the inp
digits is 3).

in(int n)

("Sum of digits : "+s);


("no. of digits : "+c);

pt a number then print the number in reverse order. (E.g. If the input number is 245, the

in(int number)

0, digit;

;
everseNumber*10+digit;
0;

("Reverse Number is : " +reverseNumber);


k whether a number is palindrome number or not. (Palindrome means, If the reverse of th

in(int number)

0, orgNumber = number, digit;

;
everseNumber*10+digit;
0;

everseNumber)
n ("Number is Palindrom");

n ("Number is not Palindrom");

trong number if the sum of cube of each digit of the number is equal to that number. Writ
the given number is Armstrong number or not. (E.g. 153 is a Armstrong number because

in(int number)

ber, digit;

;
w(digit,3);
0;

um)
n ("Number is Armstrong");

n ("Number is not Armstrong");


lay all three digits Armstrong number.

in()

0;number< = 999;number++)

t*digit*digit);

m)
tln ("Armstrong Number is "+number);

k whether all digits of the given number are same type or not (i.e. all are odd, all even nu

pt a number and then add all digits until you found a single digit number. If that single dig
ber. (e.g. if number is 2345 then sum of its digits becomes 14, further sum of this digits is

in(int number)
10;
;
/10;

n ("Lucky Number");

n ("Not Lucky Number");

sign Using Nested Loops:

*
***
*****
*******
*****
***
*
class ast1
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 40-i;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
System.out.print ("*");
System.out.println ();
}
for(i = 4;i> = 1;i--)
{
for(j = 1;j< = 40-i;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
System.out.print ("*");
System.out.println ();
}
}
}
*
*+*
*+++*
*+++++*
*+++++++*
*+++++*
*+++*
*+*
*
class ast2
{
public static void main(String args[])
{
int i,j,p = 40;
for(i = 1;i< = 5;i++,p--)
{
for(j = 1;j< = p;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
{
if(j = = 1 || j = = i*2-1)
System.out.print ("*");
else
System.out.print ("+");
}
System.out.println ();
}
p = p+2;
for(i = 4;i> = 1;i--,p++)
{
for(j = 1;j< = p;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
{
if(j = = 1 || j = = i*2-1)
System.out.print ("*");
else
System.out.ࡰrint("+");
}
System.out.println ();
}
}
}
*
***
*****
*******
class ast3
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 40-i;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
System.out.print ("*");
System.out.println ("");
}
}
}
*
***
*****
*******
* *
**
*
class ast4
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 40-i;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
System.out.print ("*");
System.out.println ("");
}
for(i = 4;i> = 1;i--)
{
for(j = 1;j< = 40-i;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
{
if(j = = 1 || j = = i*2-1)
System.out.print ("*");
else
System.out.print (" ");
}
System.out.println ("");
}
}
}
*
**
* *
* *
* *
**
*
class ast5
{
public static void main(String args[])
{
int i,j,p = 40;
for(i = 1;i< = 5;i++,p--)
{
for(j = 1;j< = p;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
{
if(j = = 1 || j = = i*2-1)
System.out.print ("*");
else
System.out.print (" ");
}
System.out.println ();
}
p = p+2;
for(i = 4;i> = 1;i--,p++)
{
for(j = 1;j< = p;j++)
System.out.print (" ");
for(j = 1;j< = i*2-1;j++)
{
if(j = = 1 || j = = i*2-1)
System.out.print ("*");
else
System.out.print (" ");
}
System.out.println ();
}
}
}
W
WE
WEL
WELC
WELCO
WELCOM
WELCOME
class pro
{
public static void main(String args[])
{
String x = "WELCOME";
int i,j;
int l = x.length();
for(i = 0;i< = l;i++)
{
for(j = 0;j<i;j++)
System.out.print (x.charAt(j));
System.out.println ();
}
}
}
A
Am
Ami
Amit
Amita
Amitab
Amitabh
class amitabh
{
public static void main(String args[])
{
String x = "Amitabh";
int i,j;
for(i = 0;i< = x.length();i++)
{
for(j = 0;j<i;j++)
System.out.print (x.charAt(j));
System.out.println ();
}
}
}
A
BB
CCC
DDDD
EEEEEE
class alpha1
{
public static void main(String args[])
{
int i,j,a = 65;
for(i = 1;i< = 5;i++,a++)
{
for(j = 1;j< = i;j++)
System.out.print ((char)a);
System.out.println ();
}
}
}
A
AB
ABC
ABCD
ABCDE
class alpha2
{
public static void main(String args[])
{
int i,j,a;
for(i = 1;i< = 5;i++)
{
a = 64;
for(j = 1;j< = i;j++)
System.out.print ((char)(a+j));
System.out.println ();
}
}
}
1111
2222
3333
4444
class pyr1
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 4;i++)
{
for(j = 1;j< = 4;j++)
System.out.print (i);
System.out.println ();
}
}
}
0
12
345
6789
class pyr2
{
public static void main(String args[])
{
int i,j,a = 0;
for(i = 1;i< = 4;i++)
{
for(j = 1;j< = i;j++)
{
System.out.print (a);
a++;
}
System.out.println ();
}
}
}
1
12
123
1234
12345
class pyr3
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = i;j++)
{
System.out.print (j);
}
System.out.println ();
}
}
}
1
21
321
4321
54321
class pyr4
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = i;j> = 1;j--)
{
System.out.print (j);
}
System.out.println ();
}
}
}
55555
4444
333
22
1
class pyr5
{
public static void main(String args[])
{
int i,j;
for(i = 5;i> = 1;i--)
{
for(j = i;j> = 1;j--)
System.out.print (i);
System.out.println ();
}
}
}
1
22
333
4444
55555
class pyr6
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = i;j++)
System.out.print (i);
System.out.println ();
}
}
}
54321
5432
543
54
5
class pyr7
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 5;j> = i;j--)
System.out.print (j);
System.out.println ();
}
}
}
54321
4321
321
21
1
class pyr8
{
public static void main(String args[])
{
int i,j;
for(i = 5;i> = 1;i--)
{
for(j = i;j> = 1;j--)
System.out.print (j);
System.out.println ();
}
}
}
12345
1234
123
12
1
class pyr9
{
public static void main(String args[])
{
int i,j;
for(i = 5;i> = 1;i--)
{
for(j = 1;j< = i;j++)
System.out.print (j);
System.out.println ();
}
}
}
12345
2345
345
45
5
class pyr10
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = i;j< = 5;j++)
System.out.print (j);
System.out.println ();
}
}
}
5
45
345
2345
12345
class pyr11
{
public static void main(String args[])
{
int i,j;
for(i = 5;i> = 1;i--)
{
for(j = i;j< = 5;j++)
{
System.out.print (j);
}
System.out.println ();
}
}
}
5
54
543
5432
54321
class pyr12
{
public static void main(String args[])
{
int i,j;
for(i = 5;i> = 1;i--)
{
for(j = 5;j> = i;j--)
System.out.print (j);
System.out.println ();
}
}
}
1
212
32123
4321234
543212345
class pyr13
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 5-i;j++)
System.out.print (" ");
for(j = i;j> = 1;j--)
System.out.print (j);
for(j = 2;j< = i;j++)
System.out.print (j);
System.out.println ();
}
}
}
1
121
12321
1234321
123454321
class pyr14
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 5-i;j++)
System.out.print (" ");
for(j = 1;j< = i;j++)
System.out.print (j);
for(j = i-1;j> = 1;j--)
System.out.print (j);
System.out.println ();
}
}
}
1
232
34543
4567654
567898765
67890109876
7890123210987
890123454321098
90123456765432109
class pyr15
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 9;i++)
{
for(j = 1;j< = 40-i;j++)
System.out.print (" ");
for(j = i;j< = (i*2)-1;j++)
System.out.print (j%10);
for(j = (i-1)*2;j> = i;j--)
System.out.print (j%10);
System.out.println ();
}
}
}
1
010
10101
0101010
101010101
class pyr16
{
public static void main(String args[])
{
int i,j,a;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 40-i;j++)
System.out.print (" ");
a = i;
for(j = 1;j< = i*2-1;j++,a++)
System.out.print (a%2);
System.out.println ();
}
}
}
1
123
12345
1234567
123456789
class pyr17
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 5-i;j++)
System.out.print (" ");
for(j = 1;j< = (i*2-1);j++)
System.out.print (j);
System.out.println ();
}
}
}
1
222
33333
4444444
555555555
class pyr18
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 5;i++)
{
for(j = 1;j< = 5-i;j++)
System.out.print (" ");
for(j = 1;j< = (i*2-1);j++)
System.out.print (i);
System.out.println ();
}
}
}
1 1
222 222
33333 33333
44444444444444
class pyr19
{
public static void main(String args[])
{
int i,j;
for(i = 1;i< = 4;i++)
{
for(j = 1;j< = 5-i;j++)
System.out.print (" ");
for(j = 1;j< = (i*2-1);j++)
System.out.print (i);
for(j = 1;j< = (4-i)*2;j++)
System.out.print (" ");
for(j = 1;j< = (i*2-1);j++)
System.out.print (i);
System.out.println ();
}
}

}
ICSE BlueJ String Handling
String Handling Questions for BlueJ
Home Page
(Note: All programs codes are Tested in BlueJ)
1. Accept a name and print it in reverse form. (If name is AMIT, th
class ques1
{
public static void main(String args[])
{
String n = "AMIT";
int l = n.length();
for(int i = l-1;i> = 0;i--)
{
System.out.print (n.charAt(i));
}
}
}
2. WAP to accept a name. Then display the ASCII value of each chara
class ques2
{
public static void main(String args[])
{
String n = "AMITABH";
int l = n.length();
for(int i = 0;i<l;i++)
{
int asc = (int)n.charAt(i);
System.out.println (n.charAt(i)+" --> "+asc);
}
}
}
3. WAP to read a word. Print the position of the first vowel occurr
print 'Sorry no vowel'.
class ques3
{
public static void main(String args[])
{
String n = "AMITABH";
int l = n.length();
int p = 0;
for(int i = 0;i<l;i++)
{
char c = n.charAt(i);
if(c = = 'A' || c = = 'E' || c = = 'I' || c = = 'O' || c
{
p = i+1;
break;
}
}
if(p = = 0)
System.out.println ("Vowel not found");
else
System.out.println ("Position of First Vowel "+p);
}
}
4. WAP in BASIC to take a proverbial statement (like 'Failure are t
then output the frequency of the vowels occurring in the statement.
class ques4
{
public static void main(String args[])
{
String n = "Failure are the pillars of success";
int va = 0,ve = 0,vi = 0,vo = 0,vu = 0;
for(int i = 0;i<n.length();i++)
{
char c = n.charAt(i);
if(c = = 'A' || c = = 'a') va++;
if(c = = 'E' || c = = 'e') ve++;
if(c = = 'I' || c = = 'i') vi++;
if(c = = 'O' || c = = 'o') vo++;
if(c = = 'U' || c = = 'u') vu++;
}
System.out.println ("No. of times Vowel 'A' is present : "+va);
System.out.println ("No. of times Vowel 'E' is present : "+ve);
System.out.println ("No. of times Vowel 'I' is present : "+vi);
System.out.println ("No. of times Vowel 'O' is present : "+vo);
System.out.println ("No. of times Vowel 'U' is present : "+vu);
}
}
5. WAP to enter any sentence and calculate the following:
a) Total number of digits present in it.
b) Total number of small letters and capital letters present in i
c) Total number of alphabets used in it.
d) Total number of special character used in it.
e) Total number of vowels presents in it.
f) Total Number words present in that sentence.
class ques5
{
public static void main(String args[])
{
String n = "O-16, Shiva Ganga Apartment, Sonari, Phone No. 3317
String alp = "ABCDEFGH IJKLMNOPQR STUVWXYZ";
int nd = 0,sl = 0,cl = 0,alpha = 0,nv = 0,ns = 0;
int l = n.length();
for(int i = 0;i<l;i++)
{
char c = n.charAt(i);
int asc = (int)c;
if(asc> = 48 && asc< = 57)
nd++;
if(asc> = 65 && asc< = 90)
cl++;
if(asc> = 97 && asc< = 122)
sl++;
if(c = = ' ')
ns++;
if(c = = 'A'||c = = 'a'|| c = = 'E'||c = = 'e'||c = = 'I
= = 'u')
nv++;
// calculating number of alphabets used
if(Character.isLowerCase(c))
c = Character.toUpperCase (c);
int pos = alp.indexOf(c);
if(pos! = -1)
{
alp = alp.replace(c,'0');
alpha++;
}
}
System.out.println ("Sentence is : "+n);
System.out.println ("No. of Digits (0-9) present : "+nd);
System.out.println ("No. of Small Letter : "+sl+" Capital Lette

System.out.println ("No. of Alphabet Used : "+alpha);


System.out.println ("No. of Special Character : "+(l-(nd+sl+cl+
System.out.println ("No. of Vowels present : "+nv);
System.out.println ("No. of Words present : "+(ns+1));
}
}
6. Write programs to accept any word and check whether the word is
class ques6
{
public static void main(String args[])
{
String ow = "MALAYALAM";
String rw = "";
int l = ow.length();
for(int i = l-1;i> = 0;i--)
rw = rw+ow.charAt(i);
if(ow.compareTo(rw) = = 0)
System.out.print ("Word is Palindrom");
else
System.out.print ("Word is not Palindrom");
}
}
7. WAP to accept a name (in first name & last name format), then di
TENDULKAR becomes S. TENDULKAR)
class ques7
{
public static void main(String args[])
{
String n = "SACHIN TENDULKAR";
System.out.print (n.charAt(0)+".");
int p = n.indexOf(' ');
System.out.print (n.substring(p));
}
}
8. WAP to accept a person's first, middle and last names in a strin
ARUP KUMAR DAS becomes A. K. DAS)
class ques8
{
public static void main(String args[])
{
String name = "ARUP KUMAR DAS";
System.out.print (name.charAt(0)+". ");
int firstSpace = name.indexOf(' ');
firstSpace++;
System.out.print (name.charAt(firstSpace)+".");
int secondSpace = name.indexOf(' ',firstSpace);
System.out.print (name.substring(secondSpace));
}
}
9. WAP to converting all capital letters of a string into small let
Input: MY NAME IS SUMIT Output: my name is sumit
class ques9
{
public static void main(String args[])
{
String n = "MY NAME IS SUMIT";
String u = "";
for(int i = 0;i<n.length();i++)
{
char c = n.charAt(i);
if(c> = 65 && c< = 90) c = (char)(c+32);
u = u+c;
}
System.out.println ("The Lower Case sentence is : "+u);
}
}
10. WAP to accept any name (full name) and convert it to Proper Cas
class ques10
{
public static void main(String args[])
{
String n = "ARUP KUMAR DAS";
String properCase = "";
n = n.toLowerCase();
properCase = properCase + Character.toUpperCase (n.charAt(0))
for(int i = 1;i<n.length();i++)
{
if(n.charAt(i) = = ' ')
properCase = properCase + " " + Character.toUpperCase (n.ch
else
properCase = properCase+n.charAt(i);
}
System.out.print ("Proper Case Name is :"+properCase);
}
}
11. WAP to accept any string and then convert each 'A' to 'AN' pres
remember 'A' should not be a part of a word?).
class ques11
{
public static void main(String args[])
{
String n = "I AM A GOOD BOY";
String s = "";
n = n+" ";
int p = 0,x;
while(p<n.length())
{
x = n.indexOf(' ',p);
String word = n.substring(p,x);
if(word.compareTo("A") = = 0)
s = s+" "+"AN";
else
s = s+" "+word;
p = x+1;
}
System.out.println ("The Converted sentence is : "+s);
}
}
12. Sankalp has a terrible habit of deleting the last two letters o
'O' in their place. WAP to convert a given word Exterminate or Elli
class ques12
{
public static void main(String args[])
{
String w = "EXTERMINATE";
int l = w.length();
if(w.charAt(0) = = 'E' || w.charAt(0) = = 'e')
System.out.println ("Word is : "+w.substring(0,l-2)+"O");
else
System.out.println ("Word is unchanged : "+w);
}
}
13. In Piglatin a word such as KING becomes INGKAY, TROUBLE becomes
word becomes the starting of the translation and proceeding letter
that begins with a vowel is left unchanged. WAP to accept a word an
class ques13
{
public static void main(String args[])
{
String n = "TROUBLE";
int p = 0,i;
for(i = 0;i<n.length();i++)
{
char c = n.charAt(i);
if(c = = 'A' || c = = 'E' || c = = 'I' || c = = 'O' || c
}
if(i = = 0) System.out.println (n);
else System.out.println ("Piglatin word " + n.substring(i
}
}
14. Accept two strings, a word and a sentence. Then find number of
'THE' and 'THE BIG FAT THE ODORE', then the computer should display
class ques14
{
public static void main(String args[])
{
String n = "THE BIG FAT THE ODORE";
n = n+" ";
String w = "THE";
int p = 0,x,ctr = 0;
while(p<n.length())
{
x = n.indexOf(' ',p);
String word = n.substring(p,x);
if(w.compareTo(word) = = 0)
ctr++;
p = x+1;
}
System.out.println ("No. of times word "+w+" present in sentenc
}
}
15. WAP to accept a sentence then convert each character to second
and Z becomes B.
class ques15
{
public static void main(String args[])
{
String n = "WE R GOOD BOYZ";
for(int i = 0;i<n.length();i++)
{
int asc = (int)n.charAt(i);
if(asc>65 && asc< = 88)
asc+ = 2;
else
if(asc = = 89)
asc = 65;
else
if(asc = = 90)
asc = 66;
System.out.print ((char)asc);
}
}
}
16. A name is to be said as odd name if the ASCII code of each char
a name and check whether the given name is odd name or not.
class ques16
{
public static void main(String args[])
{
String n = "MOUSUMI";
int flag = 0;
for(int i = 0;i<n.length();i++)
{
int asc = (int)n.charAt(i);
if(asc%2 = = 0) flag = 1;
}
if(flag = = 0)
System.out.println (n+" is a odd Name");
else
System.out.println (n+" is not a odd Name");
}
}
17. Write a program for converting a sentence in reverse. (Input: B
class ques17
{
public static void main(String args[])
{
String n = "BlueJ is Programming";
n = n+" ";
String rs = "";
int p = 0,x;
while(p<n.length())
{
x = n.indexOf(' ',p);
String w = n.substring(p,x);
rs = w+" "+rs;
p = x+1;
}
System.out.println ("The Sentence is : "+rs);
}
}
18. Write a program to accept a binary number and convert it to dec
compliment and then convert it to decimal number.
class ques18
{
public static void main(String args[])
{
String b = "1010111";
String cb = "";
int tp = 1,dec = 0,cdec = 0;
int l = b.length();
for(int i = l-1;i> = 0;i--)
{
// calculating decimal value of binary number and compliment
if(b.charAt(i) = = '1')
{
dec = dec+(1*tp);
cdec = cdec+(0*tp);
}
else
{
dec = dec+(0*tp);
cdec = cdec+(1*tp);
}
tp* = 2;
// find out the compliment of binary number
if(b.charAt(i) = = '1')
cb = "0"+cb;
else
cb = "1"+cb;
}
System.out.println ("Binary Number : "+b+" Decimal Value : "+de
System.out.println ("Compliment of Binary number : "+cb+" Decim
}
}

You might also like