Giter VIP home page Giter VIP logo

Comments (14)

rituratnam avatar rituratnam commented on September 6, 2024 1

CODE:
package pattern21a;

/**
*

  • @author Lavalesh
    */
    public class Pattern21a {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      int i, j;
      final int N = 5;
      for (i = 1; i <= N - 2; i++) {
      for (j = 1; j <= N; j++) {
      if (j <= i || j > N - i) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }
      for (i = N - 1; i <= N; i++) {
      for (j = 1; j <= N; j++) {
      if (j <= N / 2 + 1 - (i - (N / 2 + 1)) || j >= N / 2 + 1 + (i - (N / 2 + 1))) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }
      }
      }
      Output:
      pattern21a

from java.

jagdish4249 avatar jagdish4249 commented on September 6, 2024

package pattern19;

/**
*

  • @author jagdish
    */
    public class Pattern19 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      int l = 2;
      for (int i = 2; i >= 1; i--) {
      for (int j = 3; j >= 1; j--) {
      if(i<j){
      if(j%2==0)
      System.out.print("0");
      else
      System.out.print("1");
      }
      else{
      System.out.print(" ");
      }
      }

       for (int j = 1; j <= 2; j++) {
       if(i>j)
           System.out.print(" ");
       else{
        if(j%2==0)
               System.out.print("1");
               else
               System.out.print("0");
           
       }
       
      
       }
       System.out.println("");
      

      }

      for (int j = 1; j <= 5; j++) {
      if(j%2==0)
      System.out.print("0");
      else
      System.out.print("1");
      }
      System.out.println("");

      for (int i = 2; i >= 1; i--) {
      for (int j = 1; j <= 3; j++) {
      if(i>=j){
      if(j%2==0)
      System.out.print("0");
      else
      System.out.print("1");
      }
      else{
      System.out.print(" ");
      }
      }

       for (int j = 2; j >= 1; j--) {
       if(i<j)
           System.out.print(" ");
       else{
        if(j%2==0)
               System.out.print("0");
               else
               System.out.print("1");
           
       }
       
      
       }
       System.out.println("");
      

      }

    }

}

image

from java.

raBbn avatar raBbn commented on September 6, 2024

/*

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor.
    */
    package pattern22;

/**
*

  • @author Kishorr
    */
    public class Pattern22 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      int i, j;
      final int N = 5;
      for (i = 1; i <= N - 2; i++) {
      for (j = 1; j <= N; j++) {
      if (j <= i || j > N - i) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }

      for (i = N - 1; i <= N; i++) {
      for (j = 1; j <= N; j++) {
      if (j <= N / 2 + 1 - (i - (N / 2 + 1)) || j >= N / 2 + 1 + (i - (N / 2 + 1))) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }
      }

}
capture18

from java.

pujanchangubhari73 avatar pujanchangubhari73 commented on September 6, 2024

package forpattern34;

/**
*

  • @author Pujan
    */
    public class ForPattern34 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      int n = 4;
      int m = n / 2;
      for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
      if (j == 0 || j == n) {

               System.out.printf("1" + " ");
           } else if (i == m && j == m) {
               System.out.printf("1" + " ");
           } else if (i == m) {
               System.out.printf("1" + " ");
           } else if (i == 0 || i == n) {
               System.out.printf(" " + " ");
           } else if (i - j == 0 || i - j == 2) {
               System.out.printf("0" + " ");
           } else if (i - j == 0 || j - i == 2) {
               System.out.printf("0" + " ");
           } else if (i - j == -1 || j - i == -1) {
               System.out.printf(" " + " ");
           }
      
       }
      
       System.out.printf("\n");
      

      }
      }

}
capture

from java.

milan604 avatar milan604 commented on September 6, 2024

package pattern20_alt;

/**
*

  • @author m-lan
    */
    public class Pattern20_alt {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      int n = 5, a = 1, b = n, mid, c, d;
      mid = (a + n) / 2;
      c = mid + 1;
      d = mid - 1;

      for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
      if ((i == a) && (j > a && j < b)) {
      System.out.printf(" ");

           } else if ((i == c) && (j > d && j < c)) {
               System.out.printf("  ");
      
           } else {
               if (j % 2 == 0) {
                   System.out.printf("0 ");
               } else {
                   System.out.printf("1 ");
               }
           }
      
       }
       if (i > mid) {
           c++;
           d--;
       }
       a++;
       b--;
       System.out.println("");
      

      }
      }

}
screenshot from 2017-07-27 16-55-42

from java.

kiir33 avatar kiir33 commented on September 6, 2024

package pattern11;

/**
*

  • @author KIRANN
    */
    public class Pattern11 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      int i, j;
      final int N = 5, M = N / 2 + 1;
      for (i = 1; i <= N - M; i++) {
      for (j = 1; j <= N; j++) {
      if (j <= i || j > N - i) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }

      for (i = N - M + 1; i <= N; i++) {
      for (j = 1; j <= N; j++) {
      if (j <= M - (i - M) || j >= i) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }
      }

}
Output:
capture

from java.

karmi214 avatar karmi214 commented on September 6, 2024

/*

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor.
    */
    package pattern22;

/**
*

  • @author Anish
    */
    public class Pattern22 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
      if (j <= i) {
      System.out.print((j + 1) % 2 + " ");
      } else {
      System.out.print(" ");
      }
      }
      for (int j = 3; j < 5; j++) {
      if ((j - i) == 3 && j != 4) {
      System.out.print(" ");
      } else {
      System.out.print((j + 1) % 2 + " ");
      }
      }
      System.out.println("");
      }
      for (int i = 2; i > 0; i--) {
      for (int j = 0; j < 3; j++) {
      if (j < i) {
      System.out.print((j + 1) % 2 + " ");
      } else {
      System.out.print(" ");
      }
      }
      for (int j = 3; j < 5; j++) {
      if ((j - i) == 2 && j != 4) {
      System.out.print(" ");
      } else {
      System.out.print((j + 1) % 2 + " ");
      }
      }
      System.out.println("");
      }

    }

}
p22

from java.

sajanbasnet75 avatar sajanbasnet75 commented on September 6, 2024

/*

To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
/
package assignment2;
/*
*

@author LORDsajan
*/
public class Assignment2 {

/**

@param args the command line arguments
/
public static void main(String[] args) {
System.out.println("\nPattern21");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (j <= i) {
System.out.print((j + 1) % 2 + " ");
} else {
System.out.print(" ");
}
}
for (int j = 3; j < 5; j++) {
if ((j - i) == 3 && j != 4) {
System.out.print(" ");
} else {
System.out.print((j + 1) % 2 + " ");
}
}
System.out.println("");
}
for (int i = 2; i > 0; i--) {
for (int j = 0; j < 3; j++) {
if (j < i) {
System.out.print((j + 1) % 2 + " ");
} else {
System.out.print(" ");
}
}
for (int j = 3; j < 5; j++) {
if ((j - i) == 2 && j != 4) {
System.out.print(" ");
} else {
System.out.print((j + 1) % 2 + " ");
}
}
System.out.println("");
}
}
}
21

from java.

leoprabin10 avatar leoprabin10 commented on September 6, 2024

public class Pattern20 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    final int N = 5, M = N / 2 + 1;
    for (int i = 1; i <= N - M; i++) {
        for (int j = 1; j <= N; j++) {
            if (j <= i || j > N - i) {
                if (j % 2 == 1) {
                    System.out.print("1 ");
                } else {
                    System.out.print("0 ");
                }
            } else {
                System.out.print("  ");
            }
        }
        System.out.println();
    }

    for (int i = N - M + 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (j <= M - (i - M) || j >= M + (i - M)) {
                if (j % 2 == 1) {
                    System.out.print("1 ");
                } else {
                    System.out.print("0 ");
                }
            } else {
                System.out.print("  ");
            }
        }
        System.out.println();
    }
}

}
p20

from java.

Sudan15423 avatar Sudan15423 commented on September 6, 2024

/*

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor.
    */
    package day4;

/**
*

  • @author dragon15423
    */
    public class Day4 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      for (int i = 0; i <= 2; i++) {
      for (int j = 0; j <= i; j++) {
      if (j == 1) {
      System.out.print(" 0 ");
      } else {
      System.out.print(" 1 ");
      }
      }
      for (int j = 3 - i; j > i; j--) {
      System.out.print(" ");
      }
      for (int j = i; j >= 0; j--) {
      if (j != 2 && j == 0) {
      System.out.print(" 1 ");
      }
      if (j == 1) {
      System.out.print(" 0 ");
      }
      }
      System.out.println();
      }
      for (int i = 0; i < 2; i++) {

       for (int k = 1; k >= i; k--) {
      
           if (k == 0) {
               System.out.print(" 0 ");
           } else {
               System.out.print(" 1 ");
           }
       }
       for (int j = 3; j <= 3 + i; j++) {
           System.out.print("   ");
           if (j == 4) {
               System.out.print("   ");
           }
       }
       for (int j = i; j < 2; j++) {
           if (j == 1) {
               System.out.print(" 1 ");
           } else {
               System.out.print(" 0 ");
           }
       }
       System.out.println();
      

      }
      }
      Output:
      22

from java.

ajay987 avatar ajay987 commented on September 6, 2024

int i, j;
final int N = 5;
for (i = 1; i <= N - 2; i++) {
for (j = 1; j <= N; j++) {
if (j <= i || j > N - i) {
if (j % 2 == 1) {
System.out.print("1\t");
} else {
System.out.print("0\t");
}
} else {
System.out.print("\t");
}
}
System.out.println("");
}

    for (i = N - 1; i <= N; i++) {
        for (j = 1; j <= N; j++) {
            if (j <= N / 2 + 1 - (i - (N / 2 + 1)) || j >= N / 2 + 1 + (i - (N / 2 + 1))) {
                if (j % 2 == 1) {
                    System.out.print("1\t");
                } else {
                    System.out.print("0\t");
                }
            } else {
                System.out.print(" \t");
            }
        }
        System.out.println("");
    }
}

patt21sol

from java.

duwalshraddha avatar duwalshraddha commented on September 6, 2024

Code
package pattern23;

/**
*

  • @author Lenovo
    */
    public class Pattern23 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      final int a = 5, b = a / 2 + 1;
      for (int i = 1; i <= a - b; i++) {
      for (int j = 1; j <= a; j++) {
      if (j <= i || j > a - i) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }

      for (int i = a - b + 1; i <= a; i++) {
      for (int j = 1; j <= a; j++) {
      if (j <= b - (i - b) || j >= i) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }
      }
      }
      22

from java.

SusanCB avatar SusanCB commented on September 6, 2024

/*

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor.
    */
    package pat20;

/**
*

  • @author nissus
    */
    public class Pat20 {

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      // TODO code application logic here
      int i, j;
      final int N = 5;
      for (i = 1; i <= N - 2; i++) {
      for (j = 1; j <= N; j++) {
      if (j <= i || j > N - i) {
      if (j % 2 == 1) {
      System.out.print("1\t");
      } else {
      System.out.print("0\t");
      }
      } else {
      System.out.print("\t");
      }
      }
      System.out.println("");
      }

for (i = N - 1; i <= N; i++) {
for (j = 1; j <= N; j++) {
if (j <= N / 2 + 1 - (i - (N / 2 + 1)) || j >= N / 2 + 1 + (i - (N / 2 + 1))) {
if (j % 2 == 1) {
System.out.print("1\t");
} else {
System.out.print("0\t");
}
} else {
System.out.print("\t");
}
}
System.out.println("");
}
}
}
pat20

from java.

sarumdr avatar sarumdr commented on September 6, 2024

public static void main(String[] args) {

for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= i; j++) {
if (j == 1) {
System.out.print(" 0 ");
} else {
System.out.print(" 1 ");
}
}
for (int j = 3 - i; j > i; j--) {
System.out.print(" ");
}
for (int j = i; j >= 0; j--) {
if (j != 2 && j == 0) {
System.out.print(" 1 ");
}
if (j == 1) {
System.out.print(" 0 ");
}
}
System.out.println();
}
for (int i = 0; i < 2; i++) {

for (int k = 1; k >= i; k--) {

 if (k == 0) {
     System.out.print(" 0 ");
 } else {
     System.out.print(" 1 ");
 }

}
for (int j = 3; j <= 3 + i; j++) {
System.out.print(" ");
if (j == 4) {
System.out.print(" ");
}
}
for (int j = i; j < 2; j++) {
if (j == 1) {
System.out.print(" 1 ");
} else {
System.out.print(" 0 ");
}
}
System.out.println();
}
}

OUTPUT
image

from java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.