REQUIREMENTS
System.out.print("-"); // print #
System.out.print("+"); // print +
System.out.println(); // print a newline
Example of the program output:
Example 1:
Enter the number: 5
The pattern is as follows:
-----++++-
----++++--
---++++---
--++++----
-++++-----
Example 2:
Enter the number: 7
The pattern is as follows:
-------++++++-
------++++++--
-----++++++---
----++++++----
---++++++-----
--++++++------
-++++++-------
//TestCode.java import java.util.Scanner; public class TestCode { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n; System.out.print("Enter the number: "); n = scan.nextInt(); System.out.println("The pattern is as follows:"); for(int i = 0;i<n;i++){ for(int j=i;j<n;j++){ System.out.print("-"); } for(int j=1;j<n;j++){ System.out.print("+"); } for(int j=0;j<=i;j++){ System.out.print("-"); } System.out.println(); } } }
Get Answers For Free
Most questions answered within 1 hours.