├── CONTRIBUTING.md ├── README.md ├── Pattern1.java ├── Pattern2.java ├── Pattern14.java ├── Pattern3.java ├── Pattern4.java ├── Pattern6.java ├── Pattern13.java ├── Pattern5.java ├── MySQLConnect.java ├── LICENSE ├── Pattern21.java ├── PrimeNumber.java └── CODE_OF_CONDUCT.md /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Sumbit your Java Code as per Question given in issues of this directory/project. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java 2 | Get given source codes from here and upload your assignment in time ! 3 | 4 | Complete/Solve all given patterns. If you have any problem regarding these pattern generation, first run your friend's code first. 5 | 6 | Only 5 Patterns maybe hard to you: 7 | https://github.com/ErSKS/Java/issues/5 https://github.com/ErSKS/Java/issues/6 https://github.com/ErSKS/Java/issues/13 https://github.com/ErSKS/Java/issues/14 https://github.com/ErSKS/Java/issues/21 8 | -------------------------------------------------------------------------------- /Pattern1.java: -------------------------------------------------------------------------------- 1 | package pattern1; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern1 { 8 | 9 | /** 10 | * @param args the command line arguments 11 | */ 12 | public static void main(String[] args) { 13 | for (int i = 0; i < 5; i++) { 14 | for (int j = 0; j < 5; j++) { 15 | System.out.print("*"); 16 | } 17 | System.out.println(""); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Pattern2.java: -------------------------------------------------------------------------------- 1 | package pattern2; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern2 { 8 | 9 | /** 10 | * @param args the command line arguments 11 | */ 12 | public static void main(String[] args) { 13 | for (int i = 0; i < 5; i++) { 14 | for (int j = i; j < 5; j++) { 15 | System.out.print("*"); 16 | } 17 | System.out.println(""); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Pattern14.java: -------------------------------------------------------------------------------- 1 | package javapatternsmorning; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern14 { 8 | 9 | public static void p() { 10 | System.out.println("\nPattern14"); 11 | int a = 1; 12 | int n = 9; 13 | for (int i = 1; i <= n; i++) { 14 | for (int j = 0; j < i; j++) { 15 | System.out.print(a - 1); 16 | } 17 | a++; 18 | System.out.println(""); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Pattern3.java: -------------------------------------------------------------------------------- 1 | package pattern3; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern3 { 8 | 9 | /** 10 | * @param args the command line arguments 11 | */ 12 | public static void main(String[] args) { 13 | for (int i = 1; i <= 5; i++) { 14 | for (int j = 5 - i; j > 0; j--) { 15 | System.out.print(" "); 16 | } 17 | for (int j = 1; j <= i; j++) { 18 | System.out.print("*"); 19 | } 20 | System.out.println(""); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Pattern4.java: -------------------------------------------------------------------------------- 1 | package pattern4; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern4 { 8 | 9 | /** 10 | * @param args the command line arguments 11 | */ 12 | public static void main(String[] args) { 13 | for (int i = 1; i < 5; i++) { 14 | for (int j = 1; j <= i; j++) { 15 | System.out.print(" "); 16 | } 17 | for (int j = 5 - i; j > 0; j--) { 18 | System.out.print("*"); 19 | } 20 | System.out.println(""); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Pattern6.java: -------------------------------------------------------------------------------- 1 | package javapatternsmorning; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern6 { 8 | 9 | public static void p() { 10 | System.out.println("\nPattern6"); 11 | int n = 9; 12 | for (int i = 1; i <= n; i++) { 13 | for (int j = 1; j <= n - i; j++) { 14 | System.out.print(" "); 15 | } 16 | for (int k = 1; k <= i; k++) { 17 | System.out.print(" *"); 18 | } 19 | System.out.println(" "); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Pattern13.java: -------------------------------------------------------------------------------- 1 | package javapatternsmorning; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern13 { 8 | 9 | public static void p() { 10 | System.out.println("\nPattern13"); 11 | int a = 1; 12 | int n = 10; 13 | for (int i = 1; i <= n; i++) { 14 | for (int j = 0; j < i; j++) { 15 | if ((i + j) % 2 == 0) { 16 | System.out.printf("0"); 17 | } else { 18 | System.out.printf("1"); 19 | } 20 | } 21 | System.out.println(""); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Pattern5.java: -------------------------------------------------------------------------------- 1 | package javapatternsmorning; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern5 { 8 | 9 | public static void p() { 10 | System.out.println("\nPattern5"); 11 | int n = 9; 12 | for (int i = 1; i <= n; i++) { 13 | for (int j = n - i; j > 0; j--) { 14 | System.out.print(" "); 15 | } 16 | for (int j = 1; j <= i; j++) { 17 | System.out.print("*"); 18 | } 19 | System.out.println(""); 20 | } 21 | for (int i = 1; i < n; i++) { 22 | for (int j = 1; j <= i; j++) { 23 | System.out.print(" "); 24 | } 25 | for (int j = n - i; j > 0; j--) { 26 | System.out.print("*"); 27 | } 28 | System.out.println(""); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /MySQLConnect.java: -------------------------------------------------------------------------------- 1 | package proj_mysqlconnect; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | import javax.swing.JOptionPane; 7 | 8 | /** 9 | * 10 | * @author ErSKS 11 | */ 12 | public class MySQLConnect { 13 | 14 | public static Connection conn; 15 | 16 | public static Connection connectDb() { 17 | try { 18 | Class.forName("com.mysql.jdbc.Driver"); 19 | conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_db", "java", ""); 20 | System.out.println("Database Connected Successfully !"); 21 | return conn; 22 | } catch (ClassNotFoundException | SQLException e) { 23 | System.out.println(e.getMessage()); 24 | JOptionPane.showMessageDialog(null, "Database cannot be connected !"); 25 | System.exit(0); 26 | } 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Er. Shiva K. Shrestha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Pattern21.java: -------------------------------------------------------------------------------- 1 | package javapatternsmorning; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class Pattern21 { 8 | 9 | public static void p() { 10 | System.out.println("\nPattern21"); 11 | final int N = 15, M = N / 2 + 1; 12 | for (int i = 1; i <= N - M; i++) { 13 | for (int j = 1; j <= N; j++) { 14 | if (j <= i || j > N - i) { 15 | if (j % 2 == 1) { 16 | System.out.print("1 "); 17 | } else { 18 | System.out.print("0 "); 19 | } 20 | } else { 21 | System.out.print(" "); 22 | } 23 | } 24 | System.out.println(); 25 | } 26 | 27 | for (int i = N - M + 1; i <= N; i++) { 28 | for (int j = 1; j <= N; j++) { 29 | if (j <= M - (i - M) || j >= M + (i - M)) { 30 | if (j % 2 == 1) { 31 | System.out.print("1 "); 32 | } else { 33 | System.out.print("0 "); 34 | } 35 | } else { 36 | System.out.print(" "); 37 | } 38 | } 39 | System.out.println(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /PrimeNumber.java: -------------------------------------------------------------------------------- 1 | package cjt; 2 | 3 | /** 4 | * 5 | * @author ErSKS 6 | */ 7 | public class PrimeNumber { 8 | 9 | public static void main(String[] args) { 10 | System.out.println("Q1. Checking Prime Numbers:"); 11 | System.out.println("Prime Check: 0 false:" + isPrime(0)); 12 | System.out.println("Prime Check: 1 false:" + isPrime(1)); 13 | System.out.println("Prime Check: 2 true:" + isPrime(2)); 14 | System.out.println("Prime Check: 3 true:" + isPrime(3)); 15 | System.out.println("Prime Check: 4 false:" + isPrime(4)); 16 | System.out.println("Prime Check: -4 false:" + isPrime(-4)); 17 | 18 | System.out.println("\nGenerating Prime Numbers less than 100:"); 19 | generatePrimes(100); 20 | System.out.println("\n"); 21 | } 22 | 23 | static boolean isPrime(int n) { 24 | if (n < 2) { 25 | return false; 26 | } 27 | int countFactor = 0; 28 | boolean result = true; 29 | for (int i = 1; i < n && result == true; i++) { 30 | if (n % i == 0) { 31 | countFactor++; 32 | } 33 | if (countFactor > 1) { 34 | result = false; 35 | } 36 | } 37 | return result; 38 | } 39 | 40 | static void generatePrimes(int n) { 41 | 42 | for (int i = 1; i < n; i++) { 43 | if (isPrime(i) == true) { 44 | System.out.print(i + " "); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Behavior that contributes to creating a positive environment include: 10 | 11 | * Using Java Programming Language 12 | 13 | 14 | ## Our Responsibilities 15 | 16 | * Releasing Java Code for optimization 17 | 18 | ## Scope 19 | 20 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 21 | 22 | ## Enforcement 23 | 24 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at shrestha.shiva@hotmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 25 | 26 | 27 | ## Attribution 28 | 29 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 30 | 31 | [homepage]: http://contributor-covenant.org 32 | [version]: http://contributor-covenant.org/version/1/4/ 33 | --------------------------------------------------------------------------------