i want the logic for java program. 12345
22345
33345
44445
55555
Answers
Answered by
14
here is the logic:
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j <= i) {
System.out.print(i + " ");
} else {
System.out.print(j + " ");
}
}
System.out.println();
}
mark it as brainliest if u like it:)
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j <= i) {
System.out.print(i + " ");
} else {
System.out.print(j + " ");
}
}
System.out.println();
}
mark it as brainliest if u like it:)
Answered by
5
public class Example
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = sc.nextInt();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (j <= i)
{
System.out.print(i + " ");
}
else
{
System.out.print(j + " ");
}
}
System.out.println();
}}}
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = sc.nextInt();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (j <= i)
{
System.out.print(i + " ");
}
else
{
System.out.print(j + " ");
}
}
System.out.println();
}}}
Similar questions