Class 9 Icse Looping Practice Questions
Class 9 Icse Looping Practice Questions
1
2. WAP to print 1.0, 1.5, 2.0, 2.5 ---------n.
1 2 3 13
3. WAP to print 2
, 3
, 4
-------- 14
.
4. WAP to print the first 20 even numbers.
5. WAP to print the first 20 odd numbers.
6. WAP to print 1, 11, 111, 1111 -------------10 terms.
7. WAP to print 1, -11, 111, -111, 1111, -11111 --------------- 10 terms.
8. WAP to print the first ten terms of the Fibonacci series.
9. WAP to print 1, 2, 3, 4, 10, 5, 6, 7, 8, ----------------50 terms.
Operation on series:
10. WAP to print the result of 5*4*3*2*1.
11. WAP to print the result of 1+2+3+4+5-------------------n terms.
12. WAP to print the result of 1+11+111--------------15 terms.
1 2 3 𝑛
𝑥 𝑥 𝑥 𝑥
13. WAP to print the result of 1
+ 2
+ 3
----------------- 𝑛
.
14. WAP to print the factorial of a given number.
15. Calculate the value of xn without using Math.pow.
1 2 3 15
𝑥 𝑥 𝑥 𝑥
16. WAP to calculate 1!
+ 2!
+ 3!
------------ 15!
.
Flag Counters:
17. The accidental record of 75 drivers to be entered and find out
the number of male drivers below 20 years of age, number of
drivers from 20-30 years of age and number of drivers which are
above 30 years of age. Also find out the percentage of female
drivers with an accident.
18. WAP to enter any 20 nos. and check how many of them are
greater than 35.
2
19. WAP to enter n numbers and find out how many are less than
39.
20. Enter the age of 30 persons and find out how many are adults
and how many are children.
21. WAP to prepare a frequency distribution chart of 100 integers
ranging from 0-49. Categories must be:-
00-09
10-19
20-29
30-39
40-49
The output should contain classes and corresponding frequencies
in two separate columns.
3
● <=12:12.5
● <=20:15
● above 20:₹2/km.
The computer keeps adding the fare and displays the total fare
collected at the end. To end the program (-999) is to be entered as a
distance. In the end find out total passengers travelled and total
fare collected.
27. Enter the name of the customer and his calls. Calculate
telephone bill as per the given condition:
Fixed charges:380
free calls: 120
next 100 after free calls:rs 2/call
next 100 calls:1.5/call
and rest calls:1/call
WAP in such a way that the program should keep asking names
and calls until the name"ABCD" is entered.
28. In order to make a survey of passengers using a particular
route each passenger is asked to state the ticket he/she wants: First
Class, Second Class, daily/monthly. In the end find out the total
number of passengers using the particular route and total number
of passengers holding each type of ticket.
29. Computerised ticket counter of an underground metro rail
charges for each ride in the following conditions:
Age Group Rate
18 & Above Rs. 5
5 or below 18 Rs. 3
Below 5 Nill
4
WAP which takes the age of various persons as input and prints their
ticket. At the end of the journey the program states the number of
passengers of different age groups who travelled and finds the total
amount of money collected as a collection of the day.
30. Enter n count of numbers and find the largest and smallest
among the lot. Also find the second largest number.
Special Numbers:
31. Write a program to check if the entered number is an
Armstrong number. (Hint: An armstrong number is a number in
which the sum of the cubes of the digits is equal to the number
itself. Sample input:153)
32. Write a program to check if the entered number is automorphic
or not.
33. Write a program to check if the number is a duck number or
not. (Hint: Duck number is a number which contains 0 as its digit.)
34. WAP to check the entered number is a BUZZ number or
not.(Hint: Buzz number is a number which is either divisible by 7
or end with 7)
35. WAP to find the LCM of two numbers
36. WAP to check whether the entered number is a Niven number
(Harshad Number) or not. (Hint: A niven number is a number
which is divisible by the sum of its digits.)
37. WAP to check whether the entered number is a neon number or
not. (Hint: A neon number is a number whose square’s digits’ sum
is equal to the number)
38. WAP to check whether the entered number is a perfect number
or not. (Hint: A perfect number is one which is equal to the sum of
its factors, excluding the number itself)
39. WAP to check whether the entered number is a prime number
or not.
5
40. WAP to check whether the entered number is a special number
or not.(Hint: If the sum of the factorial of digits of a number (N) is
equal to the number itself, the number (N) is called a special
number.)
41. WAP to check the entered number is a spy number or not.
(Hint: Spy number is a number whose sum of digits is equal to the
product of its digits)
42. WAP to check whether the entered number is a unique number
or not.(Hint: A unique number is one in which the digits are not
repeated)
43. WAP to check whether the entered number is a magic number
or not.(Hint: A magic number is a number in which the number is
equal to the product of the sum of digits and the reverse of the sum
of the digits).
44. WAP to check whether a number is a Special 2-Digit Number or
not. (Hint: A Special 2 Digit number is a number in which the sum
of the sum and product of the digits of the number is equal to the
number.) (Hint-Ex: if(sum+pro)==num))
Nested Loop:
45. WAP to print the table of all even numbers from 3-19.
46. WAP to print the table of all numbers from 3-18.
47. WAP to enter any 50 numbers and print the sum of all the
numbers from 1 to that number.
48. WAP to enter any 50 numbers and print the product of all
numbers from 1 to that number.
49. For 20 students each time enter the name of the student, roll
number and his marks in 5 subjects. (Marks must be entered using
a single variable and each time print name, roll number, total and
average marks of each student).
6
50. For 100 persons each time enter his name and his monthly
electricity bill for 12 months. For each person print the name and
electricity bill for the whole year.
51. A small address book has 5 pages; each page has 4 addresses.
WAP to find the number of persons on each page living in Park
Road Street.
Pattern Printing:
(If you want to practice more of patterns: Click Here)
52. Print the pattern given below:
55555
5555
555
55
5
53. Print the following series:
55555
4444
333
22
1
54. Print the following series:
54321
5432
543
7
54
5
55. Print the following series:
1
12
123
1234
12345
56. Print the following series:
12345
1234
123
12
1
57. Print the following series:
987654321
98765432
9876543
987654
98765
9876
987
98
8
9
58. Print the following series:
987654321
87654321
7654321
654321
54321
4321
321
21
1
59. Print the following pattern:
1
12
123
1234
12345
1234
123
12
1
60. Print the following pattern:
1
9
22
333
4444
55555
61. Print the following pattern:
987
654
321
62. Print the following pattern:
10000
01000
00100
00010
00001
63. Print the following pattern:
*
**
***
****
*****
64. Print the following pattern:
*
**
10
***
****
*****
65. Print the following pattern:
1
10
101
1010
10101
101010
1010101
66. Print the following pattern:
*****
****
***
**
*
67. Print the following pattern:
*******
*****
***
*
68. Print the following pattern:
11
*
***
*****
*******
69. Print the following pattern:
*
***
*****
*******
*****
***
*
70. WAP to print the following pattern:
2**
4****
6******
.
.
.
.
.
20 * * * * * * ………………(20*)
71. WAP to print the following pattern:
12
1*2**3***4****..........................20*****......(20*)
72. WAP to print the following pattern:
55555
44444
33333
22222
11111
73. WAP to print the following pattern:
1
123
12345
1234567
74. WAP to print the following pattern:
1
01
101
0101
10101
75. WAP to print the following pattern:
*
#*
*#*
#*#*
13
76. WAP to print the following pattern:
1
14
149
1 4 9 16
1 4 9 16 25
77. WAP to print the following pattern:
1
00
111
0000
11111
78. WAP to print the following pattern:
1
23
456
7 8 9 10
79. WAP to print the following pattern:
1
31
531
7531
97531
14
80. WAP to print the following pattern:
1
2 3
4 5 6
7 8 9 10
81. WAP to print the following pattern:
13579
1357
135
13
1
82. WAP to print the following pattern:
1234567
12345
123
1
83. WAP to print the following pattern:
9
89
789
6789
56789
456789
15
3456789
23456789
123456789
84. WAP to print the following pattern:
5
10 15
20 25 30
35 40 45 50
85. WAP to print the following pattern:
01111
00111
00011
00001
00000
86. WAP to print the following pattern:
10000
11000
11100
11110
11111
Operation On Patterns:
87. WAP to calculate the result of the following pattern expression:
1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3 + 4) + …………....20
16
Answer Key:
1. class Naturalreverse
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
for(int i=50;i>=4;i--)
{
System.out.println(i);
}
}
}
2. import java.io.*;
class Incrementofpointfive
{
public static void main(String args[])throws IOException
17
{
System.out.println('\u000C'); //Use to clear screen
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter any decimal number");
double n=Double.parseDouble(in.readLine());
for(double i=1.0;i<=n;i+=0.5)
{
System.out.println(i);
}
}
}
3. class Onebytwo
{
public static void main(String args[])
{
System.out.println('\u000C'); //Use to clear screen
for(int i=1;i<=13;i++)
{
System.out.print(i+"/"+(i+1));
if(i<=12)
System.out.print(", ");
else
System.out.print(".");
}
}
}
4. class Evennumbers
{
18
public static void main(String args[])
{
System.out.println('\u000C'); //Use to clear screen
for(int i=0;i<=40;i+=2)
{
System.out.println(i);
}
}
}
5. class Oddnumbers
{
public static void main(String args[])
{
System.out.println('\u000C'); //Use to clear screen
for(int i=1;i<=39;i+=2)
{
System.out.println(i);
}
}
}
6. class Oneeleven
{
public static void main(String args[])
{
System.out.println('\u000C'); //Use to clear screen
int a=0;
for(int i=1;i<=15;i++)
{
a=a*10+1;
19
System.out.print(a);
if(i<=14)
System.out.print(", ");
else
System.out.print(".");
}
}
}
7. class Oneelvenpro
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
long a=0l;
System.out.println("-1");
for(int i=1;i<=10;i++)
{
a=a*10+1;
if(i%2==0)
System.out.println(a*-1);
else
System.out.println(a);
}
}
}
8. class Fibonacci
{
public static void main(int n)
{
20
System.out.println('\u000C'); //USe to clear screen
long a=0l,b=1l,sum;
for(int i=1;i<=n;i++)
{
sum=a+b;
System.out.print(sum);
if(i<=(n-1))
System.out.print(", ");
else
System.out.print(". ");
a=b;
b=sum;
}
}
}
9. class Fibonacci_Pro
{
public static void main(int n)
{
System.out.println('\u000C'); //Use to clear screen
int a=1,b=2,c=3,d=4,sum;
for(int i=1;i<=(n/5);i++)
{
sum=a+b+c+d;
System.out.print(a+", ");
System.out.print(b+", ");
System.out.print(c+", ");
System.out.print(d+", ");
System.out.print(sum);
a=a+4;
b=b+4;
21
c=c+4;
d=d+4;
if(i<=(n/5-1))
System.out.print(", ");
else
System.out.print(". ");
}
}
}
11.import java.io.*;
class Sumofi
{
public static void main(String args[])throws IOException
{
System.out.println('\u000C'); //Used to clear screen
InputStreamReader read=new InputStreamReader(System.in);
22
BufferedReader in=new BufferedReader(read);
System.out.println("Enter the number of values");
int n=Integer.parseInt(in.readLine());
int r=0;
for(int i=1;i<=n;i++)
{
r=r+i;
}
System.out.println("Sum of integers uptil "+n+" is "+r+".");
}
}
23
{
System.out.println('\u000C'); //Use to clear screen
Scanner y=new Scanner(System.in);
double r=0.0;
System.out.println("Enter the value of n");
int n=y.nextInt();
System.out.println("Enter the value of x");
int x=y.nextInt();
for(int i=1;i<=n;i++)
{
r=r+((Math.pow(x,i))/i);
}
System.out.println("Result is "+r);
}
}
24
}
}
25
for(int i=1;i<=15;i++)
{
p=p*i;
r=r+((Math.pow(x,i))/p);
}
System.out.println(r);
}
}
17. import java.io.*;
class Accident
{
public static void main(String args[])throws IOException
{
System.out.println('\u000C'); //Use to clear screen
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int a=0,b=0,c=0,age,male=0,female=0;
for(int i=1;i<=75;i++)
{
System.out.println("Enter your gender");
char g=(char)(in.read());
if(g=='m'||g=='M')
{
male++;
System.out.println("Enter your age");
age=Integer.parseInt(in.readLine());
if(age<=20)
a++;
else if(age<=30)
26
b++;
else if(age>30)
c++;
}
else if(g=='f'||g=='F')
female++;
else if(g!='f'||g!='F'||g!='m'||g!='M')
System.out.println("Invalid Input");
}
System.out.println("Number of male drivers who met with an accident
BELOW TWENTY years of age:- "+a);
System.out.println("Number of male drivers who met with an accident
BETWEEN TWENTY AND THIRTY years of age:- "+b);
System.out.println("Number of male drivers who met with an accident
ABOVE THIRTY years of age:- "+c);
System.out.println("Number of female drivers who met with an
accident:- "+female);
System.out.println("Percentage of female drivers who met with an
accident:- "+((female/75.0)*100)+"%");
}
}
27
System.out.println("Enter any twenty numbers one by one");
int n=y.nextInt();
if(n>35)
a++;
}
System.out.println(a+" numbers are greater than 35");
}
}
28
20. import java.util.*;
class Ageof30
{
public static void main(String args[])
{
System.out.println('\u000C'); //Use to clear screen
Scanner y=new Scanner(System.in); //Creation of object of scanner
class
int a=0;
int child=0,adult=0;
for(int i=1;i<=30;i++)
{
System.out.println("Enter any 30 numbers");
int n=y.nextInt();
if(n<18)
child++;
else if(n>18)
adult++;
}
System.out.println("The number of adults is "+adult);
System.out.println("The number of children is "+child);
}
}
29
int a=0,b=0,c=0,d=0,e=0;
for(int i=1;i<=10;i++)
{
System.out.println("Enter any number between 0-49");
int n=Integer.parseInt(in.readLine());
if(n<10)
a++;
else if(n<20)
b++;
else if(n<30)
c++;
else if(n<40)
d++;
else if(n<50)
e++;
else
System.out.println("Invalid Input");
}
System.out.println("Class"+"\t"+"Frequncy");
System.out.println("00-09"+"\t"+a);
System.out.println("10-19"+"\t"+b);
System.out.println("20-29"+"\t"+c);
System.out.println("30-39"+"\t"+d);
System.out.println("40-49"+"\t"+e);
}
}
30
System.out.println('\u000C');//use to clear the screen
Scanner y=new Scanner(System.in);
sq= sq+(n*n);
abs= Math.abs(n)+abs;
if(n>0)
{
cp++;
pos=n;
sump= sump+n;
}
else if(n<0)
{
cn++;
neg=n;
sumn= sumn+n;
}
else if(z==0)
{
z++;
}//end of conditional statements
}//end of for loop
31
System.out.println("Percentage of positive numbers is:
"+(cp*100.0)/(20.0)+"%");
System.out.println("Percentage of negative numbers is:
"+(cn*100.0)/(20.0)+"%");
System.out.println("Percentage of 0s is: "+(z*100.0)/(20.0)+"%");
System.out.println("Sum of positive numbers is: "+sump);
System.out.println("Sum of negative numbers is: "+sumn);
System.out.println("Sum of all square numbers is: "+sq);
System.out.println("Sum of absolute values of entered numbers is:
"+abs);
}
}
32
ii++;
else if(ch=='o'||ch=='O')
o++;
else if(ch=='u'||ch=='U')
u++;
}
System.out.println("Class"+"\t"+"Frequency");
System.out.println("A "+"\t"+a);
System.out.println("E "+"\t"+e);
System.out.println("I "+"\t"+ii);
System.out.println("O "+"\t"+o);
System.out.println("U "+"\t"+u);
}
}
24. Will be uploaded soon…
25.
26.
import java.io.*;
class Bus
{
public static void main(String args[])throws IOException
{
System.out.println('\u000C'); //Use to clear screen
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int dis;
double bill,total=0.0;
33
do
{
System.out.println("Enter the distance you want to travel");
dis=Integer.parseInt(in.readLine());
if(dis==-999)
{
System.out.println("You chose to terminate the program");
break;
}
if(dis<=12)
{
bill=12.5;
total=total+bill;
System.out.println("Your fare is Rs. "+bill);
}
else if(dis<=20)
{
bill=20.0;
total=total+bill;
System.out.println("Your fare is Rs. "+bill);
}
else
34
{
bill=dis*2.0;
total=total+bill;
System.out.println("Your fare is Rs. "+bill);
}
}while(dis!=-999);
if(dis==-999)
System.out.println("The total fare collected today is Rs. "+total);
}
}
27.
import java.io.*;
class Tele
{
public static void main(String args[])throws IOException
{
System.out.println('\u000C'); //Use to clear screen
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
String name;
int calls,bill;
do
{
35
System.out.println("Enter your name");
name=(in.readLine());
if(name.equalsIgnoreCase("ABCD"))
{
System.out.println("You chose to terminate the program");
break;
}
System.out.println("Enter your calls");
calls=Integer.parseInt(in.readLine());
if(calls<=120)
System.out.println("Your bill is Rs. 380.0"));
else if(calls<=220)
System.out.println("Your bill is Rs. "+(380.0+((calls-120)*2.0)));
else if(calls<=380)
System.out.println("Your bill is Rs.
"+(380.0+200.0+((calls-220)*1.5)));
else
System.out.println("Your bill is Rs.
"+(380.0+200.0+150+((calls-380)*1.0)));
}while(!name.equalsIgnoreCase("ABCD"));
}
}
28. Will be uploaded soon
29. Will be uploaded soon
36
30. Will be uploaded soon
31. class Tableof3to18
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
for(int i=3;i<=18;i++)
{
System.out.println("**Table of "+i+"**");
for(int j=1;j<=10;j++)
{
System.out.println(j+" times "+i+" is "+(i*j));
}
System.out.println();
}
}
}
32. import java.util.*;
class Armstrong
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
Scanner y=new Scanner(System.in);
System.out.println("Enter a number");
int n=y.nextInt();
37
int q,sum=0,temp;
temp=n;
while(n!=0)
{
q=n%10;
sum=sum+(q*q*q);
n=n/10;
}
if(sum==temp)
System.out.println(temp+" is a Moon Citizen");
else
System.out.println(temp+" is an Earth Citizen");
}
}
33. import java.util.*;
class Autobrot
{
public static void main(String args[])
{
System.out.println('\u000c'); // used to clear screen
Scanner y=new Scanner(System.in);
int n, temp, count=0, r, sq, ld;
System.out.println("Enter any number");
n=y.nextInt();
temp=n;
while(temp!=0)
{
38
r=temp%10;
count++;
temp=temp/10;
}
sq=(int)(Math.pow(n,2));
ld=sq%((int)(Math.pow(10,count)));
if(n==ld)
System.out.println("Arey bhai bhai bhai bhai. Pro hai re tu");
else
System.out.println("Padh le Padh. Finals mein puri book aayegi");
}
}
34. import java.util.*;
class Aaronfinch
{
public static void main(String args[])
{
System.out.println('\u000C'); // used to clear screen
Scanner y=new Scanner(System.in);
int n, temp, count=0, q;
System.out.println("Enter any number");
n=y.nextInt();
temp=n;
39
while(temp!=0)
{
q=temp%10;
if(q==0)
count++;
temp=temp/10;
}
if(count ==0)
System.out.println("Nahi hai yaara");
else
System.out.println("Happy Diwali");
}
}
35. import java.util.*;
class BUZZ
{
public static void main(String args[])
{
System.out.println('\u000C'); //used to clear screen
Scanner y=new Scanner(System.in);
System.out.println("Enter the number to be checked");
int n=y.nextInt();
int temp=n;
if(n%10==7||n%7==0)
System.out.println("BUZZ");
else
System.out.println("Dengue");
40
}
}
36. import java.util.*;
class LCM
{
public static void main(String args[])
{
System.out.println('\u000C'); //used to clear screen
Scanner y=new Scanner(System.in);
System.out.println("Enter the first number");
int a=y.nextInt();
int tempa=a;
System.out.println("Enter the second number");
int b=y.nextInt();
int tempb=b;
int temp=0,gcd=0;
if(a<b)
{
temp=a;
a=b;
b=temp;
}
while(b!=0)
{
temp=b;
b=a%b;
gcd=temp;
}
System.out.println("GCD is "+gcd);
int lcm=(tempa*tempb)/gcd;
System.out.println("LCM is "+lcm);
}
}
41
37. import java.util.*;
class Scam1992
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
Scanner y=new Scanner(System.in);
System.out.println("Enter the number");
int n=y.nextInt();
int temp=n;
int q,sum=0;
while(n!=0)
{
q=n%10;
sum=sum+q;
n/=10;
}
if(temp%sum==0)
System.out.println("Scam hogaya yar");
else
System.out.println("Harshad Mehta Noob");
}
}
38. import java.util.*;
class Neon
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
Scanner y=new Scanner(System.in);
System.out.println("Enter the number");
int n=y.nextInt();
int sq=n*n;
42
int temp=n;
int temps=sq;
int q,sum=0;
while(sq!=0)
{
q=sq%10;
sum+=q;
sq=sq/10;
}
if(sum==n)
System.out.println("Neon Number");
else
System.out.println("Not a neon number");
}
}
39. Will be uploaded soon
40. import java.util.*;
class Special
{
public static void main(String args[])
{
System.out.print('\u000C'); //used to clear screen
Scanner y=new Scanner(System.in);
System.out.println("Enter number");
int n=y.nextInt();
int temp=n;
int f=1,q,sum=0;
while(n!=0)
{
q=n%10;
f=1;
for(int i=1;i<=q;i++)
f=f*i;
43
sum+=f;
n/=10;
}
if(sum==temp)
System.out.println("Special Number");
else
System.out.println("Not a special number");
}
}
44
}
}//end of code
46. class Table
{
public static void main(String args[])
{
System.out.println('\u000C');
int r;
System.out.println(r);
}
System.out.println(" ");//to print a blank
}
}
}
47. import java.util.*;
class sum50
{
public static void main(String args[])
{
System.out.println('\u000C');//use to clear the screen
Scanner y=new Scanner(System.in);
int n,s;
45
for(int i=1; i<=50; i++)
{
s=0;
System.out.println("Enter number"+i);
n= y.nextInt();
for(int i=1;i<=50;i++)
{
System.out.println("Enter number "+i);
n=y.nextInt();
prod=1;
for(int j=1;j<=n;j++)
{
prod=prod*j;
}
System.out.println("Product of all numbers till "+n+" is "+prod);
46
}
}
}
49. Will be uploaded soon
50. import java.util.*;
class Students
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
Scanner y=new Scanner(System.in);
double m,total=0,avg;
String name=""; int roll;
for(int i=1;i<=20;i++)
{
System.out.println("Enter the name");
name=y.nextLine();
System.out.println("Enter roll number");
roll=y.nextInt();
total=0.0;
avg=0.0;
for(int j=1;j<=5;j++)
{
System.out.println("Enter marks in Subject "+j);
m=y.nextDouble();
total=total+m;
}
avg=total/5.0;
System.out.println("Total marks: "+total);
System.out.println("Average: "+avg);
}
}
}
47
51. import java.util.*;
class Bijlikabill
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
Scanner y=new Scanner(System.in);
double bill,total;
String name;
for(int i=1;i<=100;i++)
{
System.out.println("Enter name of person "+i);
name=y.nextLine();
total=0.0;
for(int j=1;j<=12;j++)
{
System.out.println("Enter bill for month "+j);
bill=y.nextDouble();
total=total+bill;
}
System.out.println("Your name is Mr./Ms. "+name);
System.out.println("Your annual bill is Rs. "+total);
}
}
}
48
String add;
int c=0;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=4;j++)
{
System.out.println("Enter address "+j+" on page "+i);
add=y.nextLine();
if(add.equalsIgnoreCase("Park Street"))
c++;
}
System.out.println("Number of people on page "+i+" living in Park
Street are "+c+".");
c=0;
}
}
}
class All5
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
for(int i=1;i<=5;i++)
{
for(int j=5;j>=i;j--)
{
System.out.print("5");
}
System.out.println();
}
}
}
49
53. class Fivetoone
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
for(int i=5;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}
}
}
54.
class PatternBoi2
{
public static void main(String args[])
{
System.out.println('\u000c'); // used to clear screen
for(int i=1; i<=5; i++)
{
for(int j=5; j>=i;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}
55. class Patter4
50
{
public static void main(String args[])
{
System.out.println('\u000c');// used to clear screen
for(int i=1; i<=5; i++)
{
for(int j=1; j<=i; j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
56. class Patter5
{
public static void main(String args[])
{
System.out.println('\u000c');// used to clear screen
for(int i=5; i>=1; i--)
{
for(int j=1; j<=i; j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
51
57. class Nineeight
{
public static void main(String args[])
{
System.out.println('\u000C'); //Used to clear screen
for(int i=1;i<=9;i++)
{
for(int j=9;j>=i;j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
52
{
public static void main(String args[])
{
System.out.print('\u000C'); //used to clear screen
for(int i=1;i<=5;i++)//beginning of for1
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}//end of for1
for(int i=4;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
53
}
System.out.println();
}
}
}
54
if(i==j)
System.out.print("1 ");
else
System.out.print("0 ");
}
System.out.println();
}
}
}
55
System.out.println(for(int i=1;i<=5;i++)
{
for(int j=0;j<(5-i);j++)
{
System.out.print(" ");
}
for(int j=0;j<i;j++)
{
);
}
}
}
56
{
public static void main(String args[])
{
System.out.println('\u000C'); //used to clear scren
int p=25;
for(int i=5;i>=1;i--)
{
for(int j=1;j<=p;j++)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
p++;
}
}
}
57
for(int k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
p++;
}
}
}
58
{
public static void main(String args[])
{
System.out.println('\u000C'); //Usd to clear screen
int p=30;
for(int i=1;i<=5;i+=2)
{
for(int j=1;j<=p;j++)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
p--;
}
for(int i=7;i>=1;i-=2)
{
for(int j=1;j<=p;j++)
{
System.out.print(" ");
}
for(int k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
p++;
}
}
}
59
70. class Twostars
{
public static void main(String args[])
{
System.out.print('\u000C'); //Used to clear screen
for(int i=2;i<=20;i+=2)
{
System.out.print(i);
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
60
}
61
System.out.println();
}
}
}
62
System.out.println();
}
}
}
63
for(int j=1;j<=i;j++)
{
System.out.print(k+" ");
k++;
}
System.out.println();
}
}
}
64
{
System.out.print('\u000C'); //used to clear screen
int p=50;
int n=1;
for(int i=1;i<=4;i++)
{
for(int j=1;j<=p;j++)
System.out.print(" ");
for(int k=1;k<=i;k++)
{
System.out.print(n);
n++;
}
p--;
System.out.println();
}
}
}
65
82. class Oneto7
{
public static void main(String args[])
{
System.out.print('\u000C'); //used to clear screen
for(int i=7;i>=1;i-=2)
{
for(int j=1;j<=i;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
66
{
public static void main(String args[])
{
System.out.print('\u000C'); //used to clear screen
int p=5;
for(int i=1;i<=4;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(p+" ");
p+=5;
}
System.out.println();
}
}
}
67
}
}
68
sum=sum+j;
}
}
System.out.println("The result is "+sum);
}
}
69