Computers and Technology

(Display four patterns using loops) Ask the user to enter an integer to
set a limit for nested loops and generate the following four patterns:

Enter an integer to be a limit of the pattern:6
Pattern A:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

Pattern B:
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Pattern C:
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1

Pattern D:
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1 Complete answer in java please. this is what i have including error message:

LoopPattern. java:1: error: class, interface, or enum expected
looppattern;
^
1 error

1 looppattern;
2 public class Looppattern{
3 public static void main(String []args){
4 scanner sc = new scanner(System. in);
5 System. out. println("Enter how man levels you need: ");
6 int levels = sc. nextInt();
7 System. out. println("\nPattern A\n");
8 for(int p=1;p<=levels;p++){
9 for(int k=1;k<=p;k++){ //increasing each level printing
10 System. out. print(k);
11 }
12 System. out. println();
13 }
14 System. out. println("\nPattern B\n");
15 int r=levels;
16 for(int p=1;p<=levels;p++){
17 for(int k=1;k<=r;k++){
18 System. out. print(k);
19 }
20 r--; //decreasing levels
21 System. out. println();
22 }
23 System. out. println("\nPattern C\n");
24 for(int p=1;p<=levels;p++){ //here incresing
25 for(int k=p;k>0;k--){ //and here decreasing pattern to achieve our required pattern
26 System. out. print(k);
27 }
28 System. out. println();
29 }
30 System. out. println("\nPattern D\n");
31 r=levels;
32 for(int p=1;p<=levels;p++){
33 for(int k=1;k<=r;k++){
34 System. out. print(k);
35 }
36 r--; //decreasing levels
37 System. out. println();
38 }
39 }
40 }

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 15:30, austintules2005
Communication is the exchange of information. true or false?
Answers: 1
image
Computers and Technology, 22.06.2019 22:10, Metlife
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
image
Computers and Technology, 23.06.2019 07:30, cireland
Write a program that inserts the digits of an integer into an array in originalorderfollowed by reverse order. first, promptthe user to enter a positive integer(> 0). determine the number of digits of the integer. create a dynamically allocated integer arrayof a size twice the number of digits. now insert the digits in original order which will occupy half of the array. then, insert the digits in reverse order. finally, output thedigits in thearray. use at least two functions to organize your program.
Answers: 3
image
Computers and Technology, 24.06.2019 01:30, kellygaytan
Suppose a cpu with a write-through, write-allocate cache achieves a cpi of 2. what are the read and write bandwidths (measured by bytes per cycle) between ram and the cache? (assume each miss generates a request for one block.)
Answers: 1
Do you know the correct answer?
(Display four patterns using loops) Ask the user to enter an integer to
set a limit for nested...

Questions in other subjects: