diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..e410ec3 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,32 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +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. + +## Our Standards + +Behavior that contributes to creating a positive environment include: + +* Using Java Programming Language + + +## Our Responsibilities + +* Releasing Java Code for optimization + +## Scope + +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. + +## Enforcement + +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. + + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ae15e8d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +Sumbit your Java Code as per Question given in issues of this directory/project. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d46c4f5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Er. Shiva K. Shrestha + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MySQLConnect.java b/MySQLConnect.java new file mode 100644 index 0000000..56c9568 --- /dev/null +++ b/MySQLConnect.java @@ -0,0 +1,29 @@ +package proj_mysqlconnect; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import javax.swing.JOptionPane; + +/** + * + * @author ErSKS + */ +public class MySQLConnect { + + public static Connection conn; + + public static Connection connectDb() { + try { + Class.forName("com.mysql.jdbc.Driver"); + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_db", "java", ""); + System.out.println("Database Connected Successfully !"); + return conn; + } catch (ClassNotFoundException | SQLException e) { + System.out.println(e.getMessage()); + JOptionPane.showMessageDialog(null, "Database cannot be connected !"); + System.exit(0); + } + return null; + } +} diff --git a/Pattern13.java b/Pattern13.java new file mode 100644 index 0000000..bb163cf --- /dev/null +++ b/Pattern13.java @@ -0,0 +1,24 @@ +package javapatternsmorning; + +/** + * + * @author ErSKS + */ +public class Pattern13 { + + public static void p() { + System.out.println("\nPattern13"); + int a = 1; + int n = 10; + for (int i = 1; i <= n; i++) { + for (int j = 0; j < i; j++) { + if ((i + j) % 2 == 0) { + System.out.printf("0"); + } else { + System.out.printf("1"); + } + } + System.out.println(""); + } + } +} diff --git a/Pattern14.java b/Pattern14.java new file mode 100644 index 0000000..ec4fac1 --- /dev/null +++ b/Pattern14.java @@ -0,0 +1,21 @@ +package javapatternsmorning; + +/** + * + * @author ErSKS + */ +public class Pattern14 { + + public static void p() { + System.out.println("\nPattern14"); + int a = 1; + int n = 9; + for (int i = 1; i <= n; i++) { + for (int j = 0; j < i; j++) { + System.out.print(a - 1); + } + a++; + System.out.println(""); + } + } +} diff --git a/Pattern21.java b/Pattern21.java new file mode 100644 index 0000000..6385e5b --- /dev/null +++ b/Pattern21.java @@ -0,0 +1,42 @@ +package javapatternsmorning; + +/** + * + * @author ErSKS + */ +public class Pattern21 { + + public static void p() { + System.out.println("\nPattern21"); + final int N = 15, 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(); + } + } +} diff --git a/Pattern5.java b/Pattern5.java new file mode 100644 index 0000000..b4094a4 --- /dev/null +++ b/Pattern5.java @@ -0,0 +1,31 @@ +package javapatternsmorning; + +/** + * + * @author ErSKS + */ +public class Pattern5 { + + public static void p() { + System.out.println("\nPattern5"); + int n = 9; + for (int i = 1; i <= n; i++) { + for (int j = n - i; j > 0; j--) { + System.out.print(" "); + } + for (int j = 1; j <= i; j++) { + System.out.print("*"); + } + System.out.println(""); + } + for (int i = 1; i < n; i++) { + for (int j = 1; j <= i; j++) { + System.out.print(" "); + } + for (int j = n - i; j > 0; j--) { + System.out.print("*"); + } + System.out.println(""); + } + } +} diff --git a/PrimeNumber.java b/PrimeNumber.java new file mode 100644 index 0000000..53a2010 --- /dev/null +++ b/PrimeNumber.java @@ -0,0 +1,48 @@ +package cjt; + +/** + * + * @author ErSKS + */ +public class PrimeNumber { + + public static void main(String[] args) { + System.out.println("Q1. Checking Prime Numbers:"); + System.out.println("Prime Check: 0 false:" + isPrime(0)); + System.out.println("Prime Check: 1 false:" + isPrime(1)); + System.out.println("Prime Check: 2 true:" + isPrime(2)); + System.out.println("Prime Check: 3 true:" + isPrime(3)); + System.out.println("Prime Check: 4 false:" + isPrime(4)); + System.out.println("Prime Check: -4 false:" + isPrime(-4)); + + System.out.println("\nGenerating Prime Numbers less than 100:"); + generatePrimes(100); + System.out.println("\n"); + } + + static boolean isPrime(int n) { + if (n < 2) { + return false; + } + int countFactor = 0; + boolean result = true; + for (int i = 1; i < n && result == true; i++) { + if (n % i == 0) { + countFactor++; + } + if (countFactor > 1) { + result = false; + } + } + return result; + } + + static void generatePrimes(int n) { + + for (int i = 1; i < n; i++) { + if (isPrime(i) == true) { + System.out.print(i + " "); + } + } + } +}