From df53417e86d06ae2c2503440d1f78bd5dfe15b2d Mon Sep 17 00:00:00 2001 From: "Er. Shiva K. Shrestha" Date: Sun, 13 Aug 2017 07:32:00 +0545 Subject: [PATCH 1/3] Prime Number Checker --- PrimeNumber.java | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 PrimeNumber.java 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 + " "); + } + } + } +} From 97cb62e3d88445f9d184f0a06ed896fd7b8fa717 Mon Sep 17 00:00:00 2001 From: "Er. Shiva K. Shrestha" Date: Fri, 25 Aug 2017 06:13:39 +0545 Subject: [PATCH 2/3] Code for MySQL Database Connection --- MySQLConnect.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 MySQLConnect.java diff --git a/MySQLConnect.java b/MySQLConnect.java new file mode 100644 index 0000000..5aca958 --- /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/cjt_db", "nepal", "Kt6tRCbCjq7PzXx9"); + 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; + } +} From e2c3721c8fb387a65035455e25a04fee733edf73 Mon Sep 17 00:00:00 2001 From: "Er. Shiva K. Shrestha" Date: Sun, 27 Aug 2017 13:39:38 +0545 Subject: [PATCH 3/3] Code to Connect MySQL Database --- MySQLConnect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MySQLConnect.java b/MySQLConnect.java index 5aca958..56c9568 100644 --- a/MySQLConnect.java +++ b/MySQLConnect.java @@ -16,7 +16,7 @@ public class MySQLConnect { public static Connection connectDb() { try { Class.forName("com.mysql.jdbc.Driver"); - conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cjt_db", "nepal", "Kt6tRCbCjq7PzXx9"); + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_db", "java", ""); System.out.println("Database Connected Successfully !"); return conn; } catch (ClassNotFoundException | SQLException e) {