Computer Science, asked by Anonymous, 4 months ago

Write code segments in Java that print a square based on the specified input which indicates the size of the square. For example, if the input is 5, then the output is as follows.
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5

Answers

Answered by dattarajshinde44
1

Answer:

import java.util.*;

public class Question {

 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

   System.out.prnitln("Enter A Number");

   int a = sc.nextInt();

   int i = 1;

  for (i=1;i<=a;i++) {

   System.out.println(i);

   System.out.print(i);

   System.out.print(i);

   System.out.print(i);

   System.out.print(i);

}

}

}

Answered by anindyaadhikari13
1

Answer:-

This is the requires program.

import java.util.*;

class Program

{

public static void main()

{

int r, i,j;

System.out.print("Enter the number of rows: ");

r=new Scanner(System.in).nextInt();

for(i=1;i<=r;i++)

{

for(j=1;j<=r;j++)

System.out.print(i+" ");

System.out.println();

}

}

}

Similar questions