Question 1- Write a program to
print following pattern –
Enter the number of lines you
want: 5
1
22
333
4444
55555
|
import java.util.*;
class pattern
{
public static void
main(String args[])
{
System.out.print("Enter the number
of lines you want: ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}
}
}
|
Question 2- Write a program to print following pattern –
Enter the number of lines you
want: 5
1
12
123
1234
12345
|
import java.util.*;
class pattern
{
public static void
main(String args[])
{
System.out.print("Enter the number
of lines you want: ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
|
Question 3- Write a program to
print following pattern –
Enter the number of lines you
want: 5
*
**
***
****
*****
|
import java.util.*;
class pattern
{
public static void
main(String args[])
{
System.out.print("Enter the number
of lines you want: ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
|
Question 4- Write a program to
print following pattern –
Enter the number of lines you
want: 5
1
21
321
4321
54321
|
import java.util.*;
class pattern
{
public static void
main(String args[])
{
System.out.print("Enter the number
of lines you want: ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=i;j>=1;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}
|
No comments:
Post a Comment