Friday, December 21, 2018

Pattern Programs in Java

package programs;

public class PatternProgram1 {

/**
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

*/
public static void main(String[] args) {
for(int i =1;i<=7;i++){
for(int j =1; j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
-------------------------------------------------------------------
package programs;

public class PatternProgram2 {

/**
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
 */
public static void main(String[] args) {
for(int i =1;i<=7;i++){
for(int j =1; j<=i;j++){
System.out.print(i+" ");
}
System.out.println();
}
}
}
----------------------------------------------------------------------
package programs;

public class PatternProgram3 {

/**
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
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

 */
public static void main(String[] args) {
for(int i =1; i<=7;i++){
for(int j =1; j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
for(int i=6;i>=1;i--){
for(int j =1; j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
---------------------------------------------------------------------
package programs;

import java.util.Scanner;

public class PatternProgram5 {

/**
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
 */
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("enter input data");
int number = scanner.nextInt();
for(int i=number;i>=1; i--){
for(int j = 1; j<=i;j++){
System.out.print("*"+" ");
}
System.out.println();
}
}
}
-----------------------------------------------------------------------

package programs;

import java.util.Scanner;

public class PatternProgram6{

/**
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
 */
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("enter input data");
int number = scanner.nextInt();
for(int i =1; i<=number;i++){
for(int j = number; j>=i;j--){
System.out.print(j+" ");
}
System.out.println();
}
}
}
--------------------------------------------------------------------------
package programs;

public class PatternProgram7 {

/**
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
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

*/
public static void main(String[] args) {
for(int i =7; i>=1; i--){
for(int j =1 ; j<=i; j++){
System.out.print(j+" ");
}
System.out.println();
}
for(int k = 2; k<=7; k++){
for(int j =1 ; j<=k; j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
----------------------------------------------------------------------
package programs;

public class PatternProgram8 {

/**
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1

*/
public static void main(String[] args) {
for(int i = 1; i<=7; i++){
for(int j = 1; j<=i; j++){
System.out.print(j+" ");
}
for(int j = i-1; j>=1; j--){
System.out.print(j+" ");
}
System.out.println();
}

}
}
------------------------------------------------------------------------


1 comment:

  1. Selenium is an open-source software testing framework for automating web application testing. It validates web applications and checks compatibility issues across different
    platforms to determine whether they function correctly. Developers and testers use multiple programming languages, including Java, Python, Ruby, etc., to write Selenium test scripts that help them automate interactions with a web browser.

    ReplyDelete

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...