Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
156 views

Lab 7v3

The document describes 25 problems to solve without using arrays or strings. The problems involve printing various patterns of numbers and stars including: number lines, rectangles, triangles (left and right justified, isosceles, hollow), rhombus, palindromes, and palindromic triangles. Hints are provided such as using loops and if statements to selectively print characters based on the line and position. The overall goal is to imagine the output as a matrix and increment or decrement numbers of stars/spaces to generate the desired patterns.

Uploaded by

Samara Chaudhury
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views

Lab 7v3

The document describes 25 problems to solve without using arrays or strings. The problems involve printing various patterns of numbers and stars including: number lines, rectangles, triangles (left and right justified, isosceles, hollow), rhombus, palindromes, and palindromic triangles. Hints are provided such as using loops and if statements to selectively print characters based on the line and position. The overall goal is to imagine the output as a matrix and increment or decrement numbers of stars/spaces to generate the desired patterns.

Uploaded by

Samara Chaudhury
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab 7

Rules:
You are not allowed to use any array or String
One only line where the word String may appear is in public static void main(String [] args) {
The word char must not be anywhere in your solution

Overall hint: Imagine all outputs as a matrix of space and star. Then count spaces and
stars to find out the trend of increment or decrement of number of stars/spaces. Utilize
several IF statement to control when star will be printed, when space will be printed
and when enter will be printed.

PROBLEM 1) Number Line


Sample input:
6
Sample output
123456

PROBLEM 2) Star Line


Print as many stars as given in input
Sample input:
6
Sample output
******

PROBLEM 3) Rectangle
Sample input:
4
6
Sample output
******
******
******
******

Hint: 4 and 6 means 4 lines of stars having 6 stars in each line.

PROBLEM 4) Rectangle
Sample input:
4
6
Sample output
123456
123456
123456
123456

Hint: 4 and 6 means 4 lines of numbers having 1..6 in each line.

Page 1 of 7
PROBLEM 5) Triangle - Left Justified
Draw right angled triangle of given height
Sample input:
4
Sample output
*
**
***
****
Hint: One loop for lines, another loop for printing i number of starts when it is line i.

PROBLEM 6) Triangle - Left Justified


Draw right angled triangle of given height
Sample input:
4
Sample output
1
12
123
1234

PROBLEM 7) Triangle - Right Justified


Draw right angled triangle of given height
Sample input:
4
Sample output
*
**
***
****
Hint: Count and print appropriate number of spaces in front of stars. Notice that there is
one less space and one more star in each line.

PROBLEM 8) Triangle - Right Justified


Draw right angled triangle of given height
Sample input:
4
Sample output
1
12
123
1234

Page 2 of 7
PROBLEM 9) Triangle - Isosceles
Draw triangle of given height
Sample input 1:
3
Sample output 1:
*
***
*****

Sample input 2:
4
Sample output 2:
*
***
*****
*******

PROBLEM 10) Triangle - Isosceles


Draw triangle of given height
Sample input 1:
3
Sample output 1:
1
123
12345

Sample input 2:
4
Sample output 2:
1
123
12345
1234567

PROBLEM 11) Triangle - Right Justified


Draw right angled triangle of given height
Sample input:
4
Sample output
4
34
234
1234

Page 3 of 7
PROBLEM 12) Rhombus
Just draw the image of the above triangle once. And then, the opposite, once.
Sample input:
3
Sample output
*
***
*****
***
*

PROBLEM 13) Rhombus


Just draw the image of the above triangle once. And then, the opposite, once.
Sample input:
3
Sample output
1
123
12345
123
1

PROBLEM 14) Hollow Rectangle


Display a rectangle of given length and width.
Sample input:
4
5
Sample output
*****
* *
* *
*****

Hint 1: Print the character space ( ) in the middle.


Hint 2: You can re-use your solution to PROBLEM 2 and use if condition to selectively print first and last star of
each line and all stars of first and last line.

PROBLEM 15) Hollow Rectangle


Display a rectangle of given length and width.
Sample input:
4
5
Sample output
12345
1 5
1 5
12345

Page 4 of 7
PROBLEM 16) Hollow Triangle - Left Justified
Draw right angled triangle of given height
Sample input:
5
Sample output
*
**
* *
* *
*****

PROBLEM 17) Hollow Triangle - Left Justified


Draw right angled triangle of given height
Sample input:
5
Sample output
1
12
1 3
1 4
12345

PROBLEM 18) Hollow Triangle


Draw right angled triangle of given height
Sample input:
5
Sample output
*
**
* *
* *
*****

PROBLEM 19) Hollow Triangle - Right Justified


Draw right angled triangle of given height
Sample input:
5
Sample output
5
45
3 5
2 5
12345

Page 5 of 7
PROBLEM 20) Hollow Triangle
Draw triangle of given height
Sample input 1:
3
Sample output 1:
*
* *
*****

Sample input 2:
4
Sample output 2:
*
* *
* *
*******

PROBLEM 21) Hollow Triangle Isosceles


Draw triangle of given height
Sample input 1:
3
Sample output 1:
1
1 3
12345

Sample input 2:
4
Sample output 2:
1
1 3
1 5
1234567

PROBLEM 22) Hollow Rhombus


Just draw the image of the above triangle once. And then, the opposite, once.
Sample input:
3
Sample output
*
* *
* *
* *
*

Page 6 of 7
PROBLEM 23) Hollow Rhombus
Just draw the image of the above triangle once. And then, the opposite, once.
Sample input:
3
Sample output
1
1 3
1 5
1 3
1

PROBLEM 24) Palindrome


Sample input:
5
Sample output
123454321

PROBLEM 25) Palindromic Triangle


Sample input:
5
Sample output
1
121
12321
1234321
123454321

Page 7 of 7

You might also like