Starting from:

$35

CSE110- Lab 8 Solved

• 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: 

Sample output 
123456 

PROBLEM 2) Star Line 
Print as many stars as given in input Sample input: 

Sample output 
****** 

PROBLEM 3) Rectangle Sample input: 


Sample output 
****** 
****** 
****** 
****** 

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


PROBLEM 4) Rectangle Sample input: 


Sample output 
123456 
123456 
123456 
123456 

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


5) Triangle - Left Justified Draw right angled triangle of given height Sample input: 

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: 

Sample output 

12 
123 
1234 

PROBLEM 7) Triangle - Right Justified Draw right angled triangle of given height Sample input: 

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: 

Sample output 

12 
123 
1234 






9) Triangle - Isosceles Draw triangle of given height Sample input 1: 

Sample output 1: 

*** 
***** 

Sample input 2: 

Sample output 2: 

*** 
***** 
******* 

PROBLEM 10) Triangle - Isosceles Draw triangle of given height Sample input 1: 

Sample output 1: 

123 
12345 

Sample input 2: 

Sample output 2: 

123 
12345 
1234567 

PROBLEM 11) Triangle - Right Justified Draw right angled triangle of given height Sample input: 4 
Sample output 

34 
234 
1234 


12) Rhombus 
Just draw the image of the above triangle once. And then, the opposite, once. Sample input: 

Sample output 

*** 
***** 
*** 


PROBLEM 13) Rhombus 
Just draw the image of the above triangle once. And then, the opposite, once. Sample input: 

Sample output 

123 
12345 
123 


PROBLEM 14) Hollow Rectangle 
Display a rectangle of given length and width. 
Sample input: 


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: 


Sample output 
12345 
1 5 
1 5 
12345 


16) 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 

45 
3 5 
2 5 
12345 

20) Triangle 
Draw triangle of given height Sample input 1: 

Sample output 1: 

* * 
***** 

Sample input 2: 

Sample output 2: 

* * 
* * 
******* 

PROBLEM 21) Hollow Triangle – Isosceles Draw triangle of given height Sample input 1: 

Sample output 1: 

1 3 
12345 

Sample input 2: 

Sample output 2: 

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 

* * 
* * 
* * 


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

1 3 
1 5 
1 3 


PROBLEM 24) Palindrome Sample input: 5 
Sample output 
123454321 

PROBLEM 25) Palindromic Triangle Sample input: 5 
Sample output 

121 
12321 
1234321 
123454321 

• 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: 

Sample output 
123456 

PROBLEM 2) Star Line 
Print as many stars as given in input Sample input: 

Sample output 
****** 

PROBLEM 3) Rectangle Sample input: 


Sample output 
****** 
****** 
****** 
****** 

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


PROBLEM 4) Rectangle Sample input: 


Sample output 
123456 
123456 
123456 
123456 

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


5) Triangle - Left Justified Draw right angled triangle of given height Sample input: 

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: 

Sample output 

12 
123 
1234 

PROBLEM 7) Triangle - Right Justified Draw right angled triangle of given height Sample input: 

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: 

Sample output 

12 
123 
1234 






9) Triangle - Isosceles Draw triangle of given height Sample input 1: 

Sample output 1: 

*** 
***** 

Sample input 2: 

Sample output 2: 

*** 
***** 
******* 

PROBLEM 10) Triangle - Isosceles Draw triangle of given height Sample input 1: 

Sample output 1: 

123 
12345 

Sample input 2: 

Sample output 2: 

123 
12345 
1234567 

PROBLEM 11) Triangle - Right Justified Draw right angled triangle of given height Sample input: 4 
Sample output 

34 
234 
1234 






12) Rhombus 
Just draw the image of the above triangle once. And then, the opposite, once. Sample input: 

Sample output 

*** 
***** 
*** 


PROBLEM 13) Rhombus 
Just draw the image of the above triangle once. And then, the opposite, once. Sample input: 

Sample output 

123 
12345 
123 


PROBLEM 14) Hollow Rectangle 
Display a rectangle of given length and width. 
Sample input: 


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: 


Sample output 
12345 
1 5 
1 5 
12345 


16) 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 

45 
3 5 
2 5 
12345 

20) Triangle 
Draw triangle of given height Sample input 1: 

Sample output 1: 

* * 
***** 

Sample input 2: 

Sample output 2: 

* * 
* * 
******* 

PROBLEM 21) Hollow Triangle – Isosceles Draw triangle of given height Sample input 1: 

Sample output 1: 

1 3 
12345 

Sample input 2: 

Sample output 2: 

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 

* * 
* * 
* * 


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

1 3 
1 5 
1 3 


PROBLEM 24) Palindrome Sample input: 5 
Sample output 
123454321 

PROBLEM 25) Palindromic Triangle Sample input: 5 
Sample output 

121 
12321 
1234321 
123454321 



More products