Starting from:

$25

CSE111- Lab 1 Solved

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. Nested loop may be utilized to print multiple lines.

 

PROBLEM 1) Number Line Sample input:

6

Sample output

123456

 

PROBLEM 2) 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.

 

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

4

Sample output

1
12

123

1234

Hint: One loop for lines, another loop for printing number 1 to i when it is line i.  

 

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

4

Sample output
   1

  12

 123

1234

 

PROBLEM 5) 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 6) 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 7) Hollow Rectangle

Display a rectangle of given length and width. 

Sample input:

4

5

Sample output

12345

1   5

1   5

12345

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

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

 

 

 

 

 

 

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

Sample output

1    12 1 3 1  4

12345

 

 

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

Sample output

    5

   45

  3 5

2    5

12345

 

PROBLEM 10) 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

 

 

11) 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 12) Triangle - Right Justified Draw right angled triangle of given height Sample input: 4

Sample output

   4

  34

 234

1234

 

PROBLEM 13) Palindrome Sample input: 5

Sample output

123454321

 

PROBLEM 14) Palindromic  Triangle Sample input: 5

Sample output

    1

   121

  12321

 1234321

123454321

 

 

PROBLEM 15) Star Line

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

Sample output

******

 

 

 

 

 

16)   Rectangle using solution of PROBLEM 15) Star Line Sample input:

4

6

Sample output

******

******

******

******

 

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

 

 


17)   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 stars when it is line i.

 

PROBLEM 18) 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 19) Triangle - Isosceles Draw triangle of given height Sample input 1:

3

Sample output 1:

  *

 ***

*****

 

Sample input 2:

4

Sample output 2:

   *

  ***

 *****

*******

 

PROBLEM 20) Rhombus using PROBLEM 19) Triangle - Isosceles

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

3

Sample output

  *

 ***

*****

 ***

  *

21) Hollow Rectangle using solution of PROBLEM 16) 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 16 and use if condition to selectively print first and last star of each line and all stars of first and last line.

 

PROBLEM 22) Hollow Triangle - Left Justified using solution of PROBLEM 17) Triangle - Left Justified Draw right angled triangle of given height Sample input:

5

Sample output

*

**

*      *

*      *

*****

 

PROBLEM 23) Hollow Triangle - Right Justified using solution of PROBLEM 18) Triangle - Right Justified Draw right angled triangle of given height Sample input:

5

Sample output

    *

   **

*      *

*      *

*****

 

PROBLEM 24) Hollow  Triangle – Isosceles using solution of PROBLEM 19) Triangle - Isosceles Draw triangle of given height Sample input 1:

3

Sample output 1:

  *

*      *

*****

 

Sample input 2:

4

Sample output 2:

   *

*      *

*      *

*******

 

PROBLEM 25) Hollow  Rhombus using solution of PROBLEM 20) Rhombus  Just draw the image of the above triangle once. And then, the opposite, once. Sample input:

3

Sample output

  *

*      *

*      *

*      *

  *

 

 

26. First 15 problems from URI Online Judge (See link below) :

 

https://www.urionlinejudge.com.br/judge/en/problems/index/1

More products