Question
Using java
Write a program which asks the user for an integer and then prints the following patterns based on that integer. Input Validation For Pattern 1, the input must be a value between 1 and 999 For Pattern 2, the input must be a value between 1 and 26. Requirements: For Pattern 1: must be able to work with up to three digit numbers. You will want to use printf to get the spacing correct. For Pattern 2: make note of what is uppercase and what is lowercase. You must use for loops to solve this problem. Program must be dynamic and work for any of the valid input values. You CANNOT hardcode the output. HINT You will need to use nested loops for this one. Each pattern is its own set of nested loops.
Sample Outputs
media%2F099%2F09927fde-cb9b-4916-bae7-70
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;

import java.util.*;

class pattern

{

public static void main(String args[])

{

int p1,p2;//for pattern1 and pattern 2

int m,n;

Scanner s=new Scanner(System.in);

int flag1=1,k;

System.out.print("how many rows for pattern1 ? : ");

p1=s.nextInt();

if(p1>0 && p1<1000) flag1=0;

while(flag1==1)

{

System.out.print("how many rows for pattern1 ? : ");

p1=s.nextInt();

if(p1>0 && p1<1000) flag1=0;

}

m=p1;

System.out.println();

for(int i=1;i<=m;i++)

{

k=m;

for(int j=1;j<=i;j++)

{

System.out.print(k-- +" ");

}

System.out.println();

}

int flag2=1;

System.out.print("how many rows for pattern2 ? : ");

p2=s.nextInt();

if(p2>0 && p2<27) flag2=0;

while(flag2==1)

{

System.out.print("how many rows for pattern2 ? : ");

p2=s.nextInt();

if(p2>0 && p2<27) flag2=0;

}

n=p2;

System.out.println();

for(int i=n;i>=1;i--)

{

for(int j=1;j<=i;j++)

{

if(j%2==0)

{

System.out.print((char)(j+64+32) +" ");

}

else

{

System.out.print((char)(j+64) +" ");

}

}

System.out.println();

}

}

}

C: \Users\SARATHCHNDRANDesktop\HomeworkLib>javac pattern.java C: \Users\SARATHCHNDRANDesktop\HomeworkLib>java pattern how many rows for p

Add a comment
Know the answer?
Add Answer to:
Using java Sample Outputs Write a program which asks the user for an integer and then...
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
  • Exercise 1: Write a C++ program that asks the user to input an integer n followed...

    Exercise 1: Write a C++ program that asks the user to input an integer n followed by n other characters that will be stored in an array. We suppose here that the user will input only lowercase characters between ‘a’ and ‘z’. We also suppose that the user will input different characters. The program will then sort these characters according to an increasing order of their alphabetical order. In this exercise, feel free to use selection sort, insertion sort, or...

  • ANSWER IN C PLEASE (: ew History Bookmarks Window Help 13.16. Loops E ry> ECE 270...

    ANSWER IN C PLEASE (: ew History Bookmarks Window Help 13.16. Loops E ry> ECE 270 home > 13.16 Loops-Ex4 zyBooks catalog TO.TU LOOo Write a program that prints a pattern like the ones shown below Ask the user to input the letter that goes in the middle of the last row in the pyramid (uppercase or lowercase). The pattern should extend to the character entered. In the Example 1, the pattern is the result from an input value of...

  • Using LC3 Editor. This program accepts an integer typed in by the user, verifies that the...

    Using LC3 Editor. This program accepts an integer typed in by the user, verifies that the number is valid, and if it is valid prints the binary version of the number to the display as on the following page. Call the program part2.asm. As you can see the program rejects any input which doesn't start with a + or - sign and prints "The input is invalid." to the display. Also any integer values less than -511 or greater than...

  • C++ coding answer 5. Write a program that asks the user for a positive integer value....

    C++ coding answer 5. Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. Input Validation: Do not accept a negative starting number.

  • Write a program that prints the following pattern to the screen. (no blank lines between lines)...

    Write a program that prints the following pattern to the screen. (no blank lines between lines) You must use nested for loops. 1 212 32123 4321234 543212345 c++

  • In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • Design a Java program that asks the user to enter an integer number n and then...

    Design a Java program that asks the user to enter an integer number n and then generates an array of that many random points (x, y) with x- and y-coordinates in the range between 0 and 100. After this the program must ask the user to enter two diagonal points (x_1, y_1) and (x_2, y_2) of a rectangle with sides parallel to the coordinate axis (see the image below, where possible pairs of diagonal points are shown in red color)....

  • Write a Java program which asks the user to enter an integer x. This program prints...

    Write a Java program which asks the user to enter an integer x. This program prints the remainder of x when it is divided by 3. Example Pl ea s e e n t e r an i n t e g e r : 3 remainde r=0 Pl ea s e e n t e r an i n t e g e r : 17 remainde r=2

  • C++ Write a complete program that will prompt the user for a digit in the range...

    C++ Write a complete program that will prompt the user for a digit in the range 5 to 15. Using that digit to determin scale display the graphic shown below. Your program must use a nested loop. You may not use the string class SAMPLE RUN: Input an integer in the range 5 to 20: 100 Incorrect. The number is out of range. Input an integer in the range 5 to 20: 10 * ** *** **** ***** ****** *******...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

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