Translate
Sunday, 10 December 2017
Pattern in Java
Pattern in Java
class NumberPattern
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
User code
import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Close the resources
sc.close();
}
}
Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Subscribe to:
Comments (Atom)
Featured post
check box
<!DOCTYPE html> <html> <head> <title>Check Box</title> </head> <body> <input ty...
-
public class ChickenAndRabbits { public static void main(String arga[]) { int a=35; int b=94; int c=a*2; int d=(b-c)/2; System.out.println(...
-
<!DOCTYPE html> <html> <head> <title>List Style</title> <style> .ul1 { list-...