subject

(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 }

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 14:20, capo9972
Cengagenowv2 is a comprehensive online learning tool. using cengagenowv2, you may access all of the following except: 2. each time you log in, cengagenowv2 automatically performs a system check and informs you if your computer does not meet the cengagenowv2 system requirements. 3. which tab/page allows you to easily track your assignment scores, number of submissions, time spent, as well as the ability view assign
Answers: 3
image
Computers and Technology, 23.06.2019 03:30, mem81
How can you repin an image on your pinterest pin board a. click on the "repin" button b. click on the "add pin" button c. click on the "upload a pin" button d. click on the "save pin" button.
Answers: 2
image
Computers and Technology, 23.06.2019 19:30, alangonsales6232
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
image
Computers and Technology, 24.06.2019 02:20, Jonny13Diaz
The first time a user launches the powerpoint program, which view is shown allowing the user to access recent presentations or create new presentations based on templates?
Answers: 1
You know the right answer?
(Display four patterns using loops) Ask the user to enter an integer to
set a limit for nested...

Questions in other subjects:

Konu
Mathematics, 29.07.2020 23:01