Print the pattern by using bufferedreader
1 3 5 7 9
2 4 6 8
3 5 7
4 6
5
Answers
Answer:
Java programs to print the numbers or any other symbols in different patterns are one of the frequently asked interview programs mostly for freshers. Because, they test the candidate’s logical ability as well as coding skills which are ‘must have skills’ for any software engineer. In this post, I have collected some of the different number pattern programs in java and have tried to solve them. I hope they will be helpful for you guys.
Number Pattern Programs In Java
Pattern 1 :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
Java Program :
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();
}
}
Explanation: