Question

LABORATORY EXERCISES: Using nested for loops, write a java program to print the pattern as shown...

LABORATORY EXERCISES:

  1. Using nested for loops, write a java program to print the pattern as shown in the sample output.

The program does the following:

  • It prompts the user to enter an integer between 1 and 10.
  • It outputs the pattern shown in the sample output based on the user input.

Sample output:

Enter an integer from 1 to 10:

8

The pattern is:

x

x x

x x x

x x x x

x x x x x

x x x x x x

x x x x x x x

x x x x x x x x

Enter an integer from 1 to 10:

3

The pattern is:

x

x x

x x x

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
public class CheggPattern {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
System.out.println("enter an integer \nfrom 1 to 10:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(); //taking input

//logic begins here
System.out.println("The pattern is: \n");
for(int i=1;i<=n;i++)
{
   for(int j=1;j<=i;j++)
   {
       System.out.print("X");
   }
   System.out.println();
}
   }

}

DON'T FORGET TO LIKE.

THANKS BY HEART.

Add a comment
Know the answer?
Add Answer to:
LABORATORY EXERCISES: Using nested for loops, write a java program to print the pattern as shown...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT