Question

print this pattern in java using one inner and one outer loop. 1 2 1 3...

print this pattern in java using one inner and one outer loop.



1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1

Homework Answers

Answer #1

Program :

class Pattern
{
public static void main(String args[])
{
int r,c;
for(r=1;r<=11;r++)
{
if(r<=6)
{
for(c=r;c>=1;c--)
{
System.out.print(c+" ");
}
}
else
{
for(c=12-r;c>=1;c--)
{
System.out.print(c+" ");
}
}
System.out.println();
}
}
}

Output :

As given the pattern's sample output /structure in your question:

Program :

class Pattern
{
public static void main(String args[])
{
int r,c;
for(r=1;r<=11;r++)
{
if(r<=6)
{
for(c=r;c>=1;c--)
{
System.out.print(c+" ");
}
}
else if(r>6 && r<=9)
{
for(c=12-r;c>=1;c--)
{
System.out.print(c+" ");
}
}
System.out.println();
}
}
}

Output :

Note :

Both the programs are correct just I thought last 2 lines of your sample pattern were missing(intentionally or accidentally) so giving you two programs. first: may you wanted that way or second: you have given intentionally.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Write a java programming nested while loop where you will declare two numbers one for...
1) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner) Steps: 1) Declare the variable of outer loop int and assign value of your choice 2) Declare while condition which outer variable is less the number of your choice 3) Declare variable of inner loop int and assign the value of your choice 4) Declare while condition...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Write the C++ code using nested for loops that prints the product of the outer loop...
Write the C++ code using nested for loops that prints the product of the outer loop counter and the inner loop counter; one per line. The outer loop counter should go from 1 to 8 and the inner loop counter should go from the value of the outer loop counter to 10. Both counters should increment by 1. Use outer for the outer loop counter and inner for the inner loop counter.
Assume that the inner loop works correctly. Using a loop-invariant proof for the outer loop, formally...
Assume that the inner loop works correctly. Using a loop-invariant proof for the outer loop, formally prove that your pseudo-code correctly sorts the given array. Be sure that your loop invariant and proof cover the initialization, maintenance, and termination conditions Given code: /** * a[0:n-1] is an array of n elements. * temp is a variable to facilitate exchange. */ BubbleSort(a, n) Begin for k = 1 to n-1 increment by 1 do // where, k is for the pass...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
Write a Java program using a single multi-level nested for-loop to display the following pattern (For...
Write a Java program using a single multi-level nested for-loop to display the following pattern (For each iteration, only one character can be printed) : 1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9# 3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27# 5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other my name's Aya amro
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other The first letter A and the last letter O
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display...
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display 5 lines of smiley faces. The following would be the output of your program: Note: Sample program is in the "Important Documents", Module 6 folder) Hello:                          Bye!
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT