# Square pattern display using java

In this program, we will learn how to display the pattern of the square using Java.
We will use some while loops and for loops for the iteration.

1. Import the util class
2. Use the Scanner method for input

How to take input from the user

```Scanner scanner=new Scanner(System.in);
int userInteger;

System.out.println("please enter a number between 1 to 15");
userInteger=scanner.nextInt();
```

In this program, we have seen a scanner keyword by the help of scanner keyword we take input and we take an integer variable to store the input value.

## Java program to print square pattern

``` import java.util.*;

public class SquareDispplay{
public static void main(String s[])
{
Scanner scanner=new Scanner(System.in);
int userInteger;

System.out.println("please enter a number between 1 to 15");
userInteger=scanner.nextInt();

while(userInteger<1 || userInteger>15)
{
userInteger=scanner.nextInt();
}

for(int row = 1 ; row<=userInteger; row++)
{
for(int colum = 1; colum<=userInteger; colum++)
{
System.out.print("x");
}
System.out.print("\n");
}
}
}

```

First, we take input from the user. If the user value is less than 1 & greater than 15 the invalid input message will be shown. If the value is valid the square pattern will display. For multiple inputs, we use while loop and in the while loop we give the condition and the condition is user input value, for example, we entered the value 5, then the loop will run 5 times and the output will be like this:

```xxxxx
xxxxx
xxxxx
xxxxx
xxxxx```

Also, learn:
{"ft_lang_label":"__label__en","ft_lang_prob":0.5663506,"math_prob":0.90722454,"size":1619,"snap":"2021-31-2021-39","text_gpt3_token_len":375,"char_repetition_ratio":0.14674923,"word_repetition_ratio":0.08,"special_character_ratio":0.24274243,"punctuation_ratio":0.15432099,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.958315,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-28T06:57:04Z\",\"WARC-Record-ID\":\"<urn:uuid:b1fcd793-d25b-49e6-b776-d8491bc2d4f8>\",\"Content-Length\":\"25448\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e69c9d14-a403-4693-982c-a97cd89fa50b>\",\"WARC-Concurrent-To\":\"<urn:uuid:536a9a55-7184-45e0-bc41-89a63ddeeb28>\",\"WARC-IP-Address\":\"74.207.248.30\",\"WARC-Target-URI\":\"https://www.codespeedy.com/square-pattern-display-using-java/\",\"WARC-Payload-Digest\":\"sha1:MIODZJPD3BCB6NAS5XHCCAYZXIDMSPF2\",\"WARC-Block-Digest\":\"sha1:APOPZCP2RRGCVRWFS47M6Q6MR3GCVP3P\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153531.10_warc_CC-MAIN-20210728060744-20210728090744-00290.warc.gz\"}"}