ICSE Bluej Logical Programs
ICSE Bluej Logical Programs
Home Page
MongoDB Atlas
(A + C)1/2
class ques1
{
public static void main(String args[])
{
int a = 2,b = 3,c = 4;
double r;
double x = 6.5*Math.pow((a+b),2);
double y = 7.3*Math.sqrt(b+c);
double z = Math.sqrt(a+c);
r = (x-y)/z;
System.out.println ("The answer is : "+r);
}
}
2. WAP to calculate the Simple Interest.
class ques2
{
public static void main(String args[])
{
int p = 5000;
int r = 5;
int t = 2;
float si = (p*r*t)/100;
System.out.println ("Simple intrest = "+si);
}
}
3. Calculate the area and circumference of circle.
class ques3
{
public static void main(String args[])
{
int r = 3;
double a = 3.14*r*r;
double c = 2*3.14*r;
System.out.println ("Area of the Circle of radious "+r+" is : "+a);
System.out.println ("Circumference : "+c);
}
}
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 1/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
4. Calculate the area of a triangle.
class ques4
{
public static void main(String args[])
{
int a = 2,b = 3,c = 4;
double area;
double s = (a+b+c)/2.0;
area = Math.sqrt(s*(s-a)*(s-b)*(s-c))/(2*a*b);
System.out.println ("Area of the Triangle");
System.out.println ("of sides "+a+","+b+","+c);
System.out.println ("is : "+area);
}
}
5. Write a program with supporting documentation to enter any three real numbers and calculate X where:
X = Product of integer portion
Sum of decimal portion
class ques5
{
public static void main(String args[])
{
double n1 = 12.85,n2 = 7.19,n3 = 3.65;
int i1 = (int) n1;
int i2 = (int) n2;
int i3 = (int) n3;
double d1 = n1-i1;
double d2 = n2-i2;
double d3 = n3-i3;
double x = (i1*i2*i3)/(d1+d2+d3);
System.out.println ("The value of X is : "+x);
}
}
Questions Based on Condition:
6. WAP to check whether a number is divisible by 5 or not.
class ques6
{
public static void main(String args[])
{
int n = 10;
if(n%5 = = 0)
System.out.println ("The number "+n+" is divisible by 5");
else
System.out.println ("The number "+n+" is not divisible by 5");
}
}
7. Accept a numbers and check whether the number is divisible by both 2 and 3 or not.
class ques7
{
public static void main(String args[])
{
int n = 10;
if(n%2 = = 0 && n%3 = = 0)
System.out.println ("The number "+n+" is divisible by 2 and 3");
else
System.out.println ("The number "+n+" is not divisible by 2 and 3");
}
}
8. Write two separate programs to accept three numbers and find which one is greater (one using if statement and anot
ternary operator).
class ques8
{
public static void main(int a,int b,int c)
{
int max = (a>b) ? ((a>c)?a:c) : ((b>c)?b:c);
System.out.print ("The Highest Number is : "+max);
}
}
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 2/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
9. Accept a numbers and find out the given number is divisible by 5 or not, if not then print the nearest number from th
number which is divisible by 5.
class ques9
{
public static void main(int n)
{
int r = n%5;
if(r = = 0)
System.out.println ("The number "+n+" is divisible by 5");
else
if(r>2)
System.out.println ("The nearest number is "+(n-r+5));
else
System.out.println ("The nearest number is "+(n-r));
}
}
10. Write a program to input the basic salary of a person. He get 15% of the basic as HRA, 15% of the basic as Conveya
allowance and 10% of the basic as Entertainment allowance. The total salary is calculated by adding Basic + HRA + Conv
Entertainment Allowance. Calculate and print the total salary of person.
class ques10
{
public static void main(int basic)
{
double HRA = basic*.15;
double conveyance = basic*.15;
double entertainment = basic*.10;
double totalSalary = basic + HRA + conveyance + entertainment;
System.out.println ("Total Salary : "+totalSalary);
}
}
11. A computer salesman gets commission on the following basis:
Sales Commission Rate
Rs. 0 - 20,000 3%
Rs. 20,000 - 50,000 12%
Rs. 50,001 and more 31%
After accepting the sales as input, calculate and print his commission amount and rate of commission.
class ques11
{
public static void main(int sales)
{
int rate = 0;
double commission = 0.0;
if(sales< = 20000)
{
rate = 3;
commission = sales*.03;
}
if(sales> = 20001 && sales< = 50000)
{
rate = 12;
commission = sales*.12;
}
if(sales> = 50001)
{
rate = 31;
commission = sales*.31;
}
System.out.println ("Commission Rate : "+rate+"%");
System.out.println ("Commission Amount : "+commission);
}
}
12. Write a program to enter the three sides of a triangle. Decide whether it is a scalene, isosceles or equilateral triangle
public class ques12
{
public static void main(String args[])
{
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 3/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
int c = Integer.parseInt(args[2]);
if (a = = b && b = = c && c = = a)
System.out.println ("Equileteral Triangle");
else if (a! = b && b! = c && c! = a)
System.out.println ("Scalean Triangle");
else
System.out.println ("Isoceles Triangle");
}
}
13. A library charges fine for books returned late. Following are the fines: first five days 40 paisa per day, Six to ten days
per day, above 10 days 80 paisa per day. Design a program to calculate the fine assuming that a book is returned N days
class ques13
{
public static void main(int Ndays)
{
double fineAmount = 0;
if(Ndays< = 5)
fineAmount = Ndays*.40;
if(Ndays> = 6 && Ndays< = 10)
fineAmount = Ndays*.65;
if(Ndays>10)
fineAmount = Ndays*.80;
System.out.println ("FINE AMOUNT (Rs.) : "+fineAmount);
}
}
14. The telephone department wishes to compute monthly telephone bills for its customers using the following rules. Min
250 for first 80 message units, plus 60 paise per unit for next 60 units, plus 50 paise per unit for next 60 units, plus 40 p
unit for any units above 200. Write a program that calculates the monthly bill, with input MESSAGE (the number of mess
and CUSTNO (the registration number of a customer). Then Display the bill in following format.
CUSTOMER NO :
MESSAGE UNITS :
AMOUNT (Rs.) :
class ques14
{
public static void main(int messageUnit,int customerNo)
{
double bill = 0;
if(messageUnit< = 80)
bill = 250;
else if(messageUnit>80 && messageUnit< = 140)
bill = 250+(messageUnit-80)*0.60;
else if(messageUnit>140 && messageUnit< = 200)
bill = 250+36+(messageUnit-140)*0.50;
else if(messageUnit>200)
bill = 250+36+30+(messageUnit-200)*0.40;
System.out.println ("CUSTOMER NUMBER : "+customerNo);
System.out.println ("MESSAGE UNIT : "+messageUnit);
System.out.println ("BILL AMOUNT : "+bill);
}
}
15. A security man paid at the hourly rate (R) for the first 40 hours of work in a week. Thereafter, he is paid at 1.25 time
hourly rate (R) for the next 16 hours and at 1.5 times of the hourly rate (R) for the further hours of work in the week. Ta
numbers of hours (H) and the rate per hour (R) as input, the weekly wages (W) is to be calculated.
class ques15
{
public static void main(int H,int R)
{
double W = 0;
if(H< = 40)
W = H*R;
else if(H>40 && H< = 56)
W = 40*R+(H-40)*R*1.25;
else if(H>56)
W = 40*R+16*R*1.25+(H-56)*R*1.5;
System.out.print ("The Weekly Wages : "+W);
}
}
16. Write a program to compute BI-monthly telephone charges for subscriber. Use the following information:
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 4/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
Fixed BI-monthly rent: Rs.380
Free calls during two months: 120
Charge/call beyond free limits upto 100 calls: Rs.1
Charge per call in excess of 100 calls: Rs. 1.25
class ques16
{
public static void main(int calls)
{
double bill = 280.0;
if(calls>120 && calls< = 220)
bill = bill+(calls-120)*1;
else if(calls>220)
bill = bill+100+(calls-220)*1.25;
System.out.println ("BILL AMOUNT : "+bill);
}
}
17. Write a program to input the code of a particular item, quantity purchased and rate. Then calculate the purchased pr
print it along with gift to be presented. The gifts to the customers are given in the following manner:
Amount of Purchase (Rs.) Gift
Between 100 to 500 A key ring
Between 500 to 1000 A leather purse
Above 1000 A pocket calculator
class ques17
{
public static void main(int code, int qty, double rate)
{
double price = qty*rate;
System.out.println ("Purchase Price : "+price);
if(price> = 100 && price< = 500)
System.out.println ("Gift item : Key Ring");
if(price>500 && price< = 1000)
System.out.println ("Gift item : Leather Purse");
if(price>1000)
System.out.println ("Gift item : Pocket Calculator");
}
}
Some Questions on multiple IF condition
Q. Write a program to take the monthly salary from the user, find and display income tax with the help of the following s
Monthly Salary Income Tax
8000 or less Nil
8000-9000 20% of Monthly salary
9000-10000 30% of Monthly salary
10000 or above 40% of Monthly salary
Q. A salesman earns a commission on the value of his sales as per the following table.
Value of sales(Rs.) Commission(%)
1 - 999 1
1000 - 9999 5
10000 - 99999 10
Write a program to calculate and print the commission using sale value as input. The program is to keep on calculating t
commission for various salesmen until a sales value zero is input.
Q. A company wants to set target for each of the four regions (EAST, WEST , NORTH and SOUTH). The company allots th
percentage target for each region.
East 15%
West 25%
North 30%
South 30%
Write a program to pass through command line parameters, the total target amount proposed by the company and print
breakup of the target for each region.
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 5/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
Q. Write a program using method to calculate the salary increment of employees based on their basic pay. Calculate the
after increment.
Basic Pay Rise
10700/- 550/-
12500/- 750/-
15000/- 1050/-
Q. Write a program using the this keyword, to calculate the prize amount for a cricketer depending upon his text average
following date.
Test Average Graduate Prize Amount
> = 80 A Rs. 1,00,000.00
80> & > = 65 B Rs. 50,000.00
50> & > = 40 C Rs. 25,000.00
<40 D Rs. 10,000.00
Q. Using if-else statements write a program in java to calculate the grade as per the given criteria:
Marks Grade
> = 80 and <100 Excellent
> = 70 and <80 First Div.
> = 60 and <70 Second Div.
> = 50 and <60 Third Div.
Less than 50 Fail
Q. Write a program to assign values the variable basic salary and calculate the DA and the gross salary and print them. T
calculated as per the rules given below:
if basic< 2000 then DA is 5% of basic
if basic> = 2000 & <7000 then DA is 8% of basic
if basic> = 7000& <10000 then DA is 10% of basic
if basic> = 10000 then DA is 12% of basic
Gross Salary = Basic + DA.
Q. There are 55 employees in an organization. You have to display the number of employees getting Net-Salary above 20
taking only Basic_Salary as input and following the table given below.
Basic Salary DA (% Basic_salary) IT (% Gross_Salary)
Below 5000 8% 6%
5000 to < 10000 15% 9%
10000and above 18% 12%
Where DA and IT are Dearness Allowance and income Tax respectively.
Gross_Salary = Basic_Salary + DA
Net_Salary = Gross_Salary - IT
Q. Calculate and display the traveling allowance for 50 employees of an organization by taking distance traveled as input
organization gives traveling allowance according to the following table.
Distance Amount.
< = 20 Rs 200
>20 and < = 50 Rs 200 + Rs 5 per extra km above 20
>50 and < = 100 Rs 500 + Rs 5 per extra km above 50.
>100 Rs 15 per km.
Q. A company has 120 employees who are divided into four grades as follows:
Grade Basic( Rs. per month) D.A.(% of Basic) H.R.A.(% of Basic)
1 10,000 or more 40% 30%
2 5,000 - 10,000 40% 25%
3 < 5,000 but > 2,000 30% 20%
4 2,000 or less 30% 15%
If the salary which is the total of Basic, D.A., and H.R.A., is above Rs.50,000 per month then Income Tax at the rate of 3
annual salary exceeding 50,000 is deducted on monthly basis at source. Taking name of the employees and the Basic(m
as inputs, a pay slip, which contains Name, Basic monthly pay, DA, HRA, Monthly Income Tax and Net Monthly Salary, fo
employee is to be printed. Write a java program to perform this job.
Q. Write a program to calculate monthly telephone bill for a consumer after accept number of call according to given crit
Monthly rent Rs 400/-
No. of free calls 100
for next 150 calls Rs. 1.25/call
for extra calls Rs. 1.50/call
Q. Write a program to input the sales or any 20 sales men. Calculate and print the commission with an added allowance
The commission can be calculated by using the following table:-
Sales Commission
Upto 5000 nil
5001-8000 10%
8001-10,000 12%
10,001 Or more 15%
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 7/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
Q. Write a Java program to accept an amount from the user and hence
find in each case:-
a) No of Rs. 100 notes and the remainder amount.
b) No of Rs. 50 notes and the remainder amount.
c) No of Rs. 20 notes and the remainder amount.
d) No of Rs. 10 notes and the remainder amount.
Eg. In Rs. 542; No of Rs. 100 = 5, Remainder = Rs. 42
No of Rs. 50 = 10, Remainder = Rs. 42
No of Rs. 20 = 27, Remainder = Rs. 2.
No of Rs. 10 = 54, Remainder = Rs. 2.
Q. A class namely student has three data member Name, roll and Marks of 5 Subjects the steam is assigned based on th
criteria :
Avg. Marks Stream
90% and above science with computers
80% ___89% science without Computers
70%____79% commerce with Maths
60%___69% commerce without Maths
Write a program to declare a class student and allot the stream and print them.
Q. ABC stand decided to take charge for the parking of 2wheeler, 3wheeler and 4wheller (same charges) as per the follow
criteria:
No. of Hrs. Parked Charge
upto 8 hrs Rs 10
next 8 hrs Rs. 6 for additional 8 hours
above 16 hours Rs. 5 for each addition 8 hrs.
Input number of hours parked and prints the charges as per given criteria.
19. Display the first ten odd numbers and the sum of them.
21. The present population of a country is PO and it increases by 5% every year. The population (P) after n years is give
formula: P = PO (1.05)n. Write a program to find the population every year for the next ten years.
(e) S = X2 + X3 + X4 + X5 + X6
2! 3! 4! 5! 6!
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 10/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 11/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
f = 0;
for(i = 2;i<n;i++)
{
if(n%i = = 0)
{
f = 1;
break;
}
}
if(f = = 0)
System.out.print (n+" ");
}
}
}
30. The production (P) of crude oil of a country in millions of barrel may be estimated by the following set of equations, w
represent the times in years. P = 5+3t, for 0< = t< = 3 and P = 14+(T-5/2)^2, for t>3, Write a program to print the qu
production for every year from t = 1 to 10.
31. Write a program to accept a number then print the sum of digits and number of digits present in it. (E.g. If the input
225, the sum of digits is 9 and number of digits is 3).
class ques31
{
public static void main(int n)
{
int s = 0,c = 0,d;
while(n>0)
{
d = n%10;
s = s+d;
c = c+1;
n = n/10;
}
System.out.println ("Sum of digits : "+s);
System.out.println ("no. of digits : "+c);
}
}
32. Write a program to accept a number then print the number in reverse order. (E.g. If the input number is 245, the ou
542)
class ques32
{
public static void main(int number)
{
int reverseNumber = 0, digit;
while(number>0)
{
digit = number%10;
reverseNumber = reverseNumber*10+digit;
number = number/10;
}
System.out.println ("Reverse Number is : " +reverseNumber);
}
}
33. Write a program to check whether a number is palindrome number or not. (Palindrome means, If the reverse of the
same of original number)
class ques33
{
public static void main(int number)
{
int reverseNumber = 0, orgNumber = number, digit;
while(number>0)
{
digit = number%10;
reverseNumber = reverseNumber*10+digit;
number = number/10;
}
if(orgNumber = = reverseNumber)
System.out.println ("Number is Palindrom");
else
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 12/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
System.out.println ("Number is not Palindrom");
}
}
34. A number is called Armstrong number if the sum of cube of each digit of the number is equal to that number. Write a
to accept a number then check whether the given number is Armstrong number or not. (E.g. 153 is a Armstrong number
153 = 13 + 53 +33).
class ques34
{
public static void main(int number)
{
double sum = 0;
int orgNumber = number, digit;
while(number>0)
{
digit = number%10;
sum = sum+Math.pow(digit,3);
number = number/10;
}
if(orgNumber = = sum)
System.out.println ("Number is Armstrong");
else
System.out.println ("Number is not Armstrong");
}
}
35. Write a program to display all three digits Armstrong number.
class ques35
{
public static void main()
{
int sum;
int n, digit;
for(int number = 100;number< = 999;number++)
{
sum = 0;
n = number;
while(n>0)
{
digit = n%10;
sum = sum+(digit*digit*digit);
n = n/10;
}
if(number = = sum)
System.out.println ("Armstrong Number is "+number);
}
}
}
36. Write a program to check whether all digits of the given number are same type or not (i.e. all are odd, all even numb
both present)
37. Write a program to accept a number and then add all digits until you found a single digit number. If that single digit
1, then that number is called lucky number. (e.g. if number is 2345 then sum of its digits becomes 14, further sum of th
5, so the number is not a lucky number)
class ques37
{
public static void main(int number)
{
int sum, digit;
while(number>9)
{
sum = 0;
while(number>0)
{
digit = number%10;
sum = sum+digit;
number = number/10;
}
number = sum;
}
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 13/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
if(number = = 1)
System.out.println ("Lucky Number");
else
System.out.println ("Not Lucky Number");
}
}
38. Display the following Design 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++)
{
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 14/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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 ("");
}
}
}
*
**
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 15/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
* *
* *
* *
**
*
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
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 16/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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 ();
}
}
}
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 17/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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
{
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 18/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 19/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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--)
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 20/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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++)
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 21/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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 ();
}
}
}
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 22/23
9/13/23, 2:47 PM ICSE Bluej Logical Programs
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 ();
}
}
https://amitabhsirkiclasses.org.in/materials/icse/jlogical.htm 23/23