diff --git a/.vscode/settings.json b/.vscode/settings.json index f3b5b9c..f41bb2a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,9 @@ "if-else", "for_loop", "Class12Project", - "Inheritance" + "Inheritance", + "FinalRevision", + "" ], "java.project.outputPath": "bin", "java.project.referencedLibraries": [ diff --git a/.zed/debug.json b/.zed/debug.json new file mode 100644 index 0000000..e69de29 diff --git a/FinalRevision/Colors.java b/FinalRevision/Colors.java new file mode 100644 index 0000000..7aff448 --- /dev/null +++ b/FinalRevision/Colors.java @@ -0,0 +1,12 @@ +public class Colors { + public static final String RESET = "\u001B[0m"; + + public static final String RED = "\u001B[31m"; + public static final String GREEN = "\u001B[32m"; + public static final String YELLOW = "\u001B[33m"; + public static final String BLUE = "\u001B[34m"; + public static final String PURPLE = "\u001B[35m"; + public static final String CYAN = "\u001B[36m"; + + public static final String BOLD = "\u001B[1m"; +} \ No newline at end of file diff --git a/FinalRevision/Colsum2.java b/FinalRevision/Colsum2.java new file mode 100644 index 0000000..16fd694 --- /dev/null +++ b/FinalRevision/Colsum2.java @@ -0,0 +1,88 @@ + +import java.util.Scanner; + +public class Colsum2 { + + int mat[][], m, n; + + public Colsum2(int mm, int nn) { + m = mm; + n = nn; + + } + + void readArray() + { + mat = new int[m][n]; + Scanner x = new Scanner(System.in); + System.out.println("Enter array elements for MATRIX "+((int)(100*Math.random()))); + for(int i=0; i1) System.out.println("not prime"); + else + { + System.out.println("prime"); + p = true; + } + len=0; + if (p) { + while (inin != 0) { + int d = inin % 10; + len++; + inin/=10; + if (d != 0 && d != 1) System.exit(0); + } + if (len < 2) System.exit(0); + System.out.println("YEAHHHHH!"); + } else { + System.out.println("NAWWWWWH!"); + } + } +} diff --git a/FinalRevision/Rearrage.java b/FinalRevision/Rearrage.java new file mode 100644 index 0000000..e1561f3 --- /dev/null +++ b/FinalRevision/Rearrage.java @@ -0,0 +1,37 @@ +import java.util.Scanner; + +class Rearrange +{ + String wrd, newwrd; + + + Rearrange() + { + wrd=""; + newwrd=""; + } + + + void readword() + { + Scanner x = new Scanner(System.in); + System.out.println("Enter a word"); + wrd = x.next(); + wrd = wrd.toUpperCase(); + + } + + void freq_vow() + { + int f1=0; + int f2=0; + for(int i=0; ia[j+1]) + { + t = a[j]; + a[j] = a[j+1]; + a[j+1] = t; + } + } + } + return a; + } + static int binSearch(int [] a, int x, int high, int low) + { + if(low>high) return -1; + int mid = (low+high)/2; + + if (a[mid] > x) + return binSearch(a,x,mid-1,low); + else if (a[mid] < x) + return binSearch(a, x, high, mid+1); + else + return 67; + } + + + /** + * HARDEST SHIT EVER IG (NOT REALLY) + * CONVERTING ANY BASE TO ANY BASE? + * WHY? COZ I SAID SO + */ + + static void printBase(int num, int base) + { + if (num >= base) printBase(num/base, base); + System.out.print(Colors.GREEN+""+DIGITS[num%base]); + } + + static int printReverse(int n) + { + if(n<10) return n; + else{ + int d = n%10; + return (d*10+printReverse(n/10)); + } + } + + static int armstrongSum(int n) + { + if(n<10) return n*n*n; + int d = n%10; + return (d*d*d + armstrongSum(n/10)); + } + +} + diff --git a/FinalRevision/TestLoopOutput.java b/FinalRevision/TestLoopOutput.java new file mode 100644 index 0000000..3b4c01d --- /dev/null +++ b/FinalRevision/TestLoopOutput.java @@ -0,0 +1,19 @@ +public class TestLoopOutput { + + static void test(int count) + { + if (count==0) + { + System.out.println(" "); + } + else + { + System.out.println("Bye"+count); + test(--count); + System.out.println(" "+count); + } + } + public static void main(String[] args) { + test(4); + } +} diff --git a/PYQ/TNTYFIV/Colsum.java b/PYQ/TNTYFIV/Colsum.java new file mode 100644 index 0000000..5482b69 --- /dev/null +++ b/PYQ/TNTYFIV/Colsum.java @@ -0,0 +1,25 @@ +import java.util.Scanner; + +public class Colsum { + int mat[][] , m , n; + Colsum(int mm, int nn) + { + m = mm; + n = nn; + mat = new int[m][n]; + } + void readArray() + { + Scanner x = new Scanner(System.in); + for (int i = 0; i <= m; i++) + { + for (int j = 0; j <= n; j++) { + System.out.print("Enter element for "+i+"th row and "+j+"th column:"); + mat[i][j] = x.nextInt(); + + + } + } + + } +} diff --git a/PYQ/TNTYFIV/Perni.java b/PYQ/TNTYFIV/Perni.java new file mode 100644 index 0000000..61402f7 --- /dev/null +++ b/PYQ/TNTYFIV/Perni.java @@ -0,0 +1,54 @@ +import java.util.Scanner; + +public class Perni +{ + static int num; //to store a binary number + + Perni() + { + num = 0; + } + static void accept() + { + Scanner x = new Scanner(System.in); + System.out.println("Enter a bunary number"); + num = x.nextInt(); + x.close(); + + int t = num; + while(t!=0) + { + int d = t%10; + if (d!=0 && d!=1) + { + System.out.println("INVALID INPUT"); + System.exit(0); + } + t = t/10; + } + } + + static int countOne(int k) + { + + if(k==0) return 0; + return (k%10)+countOne(k/10); + + // if(k==0) return 0; + // return (k%10 == 1?1:0) + countOne(k/10); + } + + static void check() + { + int c = countOne(num); + if (c%2!=0) System.out.println("Perni Number"); + else System.out.println("Not Perni Number"); + } + + public static void main(String[] args) + { + Perni ob = new Perni(); + Perni.accept(); + Perni.check(); + } +} \ No newline at end of file diff --git a/README.md b/README.md index da0aa20..6a77a8d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,69 @@ -# Studying Java - java projects for school +# 📚 Java Practice Collection +A growing library of small Java programs that illustrate core language concepts – loops, conditionals, arrays, classes, inheritance, I/O, and more. + +Why this repo? +• 100+ self‑contained examples written while learning Java (2018‑2023). +• Ready to copy‑paste, compile, run, or import into any IDE. +• All files are plain .java – no external dependencies or build tools required. + +📁 Folder Overview +Folder Typical Contents / Purpose +bin/ Compiled .class files (generated automatically by javac). No source code lives here. +Class12Project/ Exercises from a 12th‑grade curriculum (e.g., simple programs, loops, conditionals). +for_loop/ Programs that demonstrate for, while, and do‑while loops – e.g., alphabet printing, array iteration. +if-else/ Examples of conditional logic (if/else, switch) plus small utility programs (electricity bill calculator, date converter). +Inheritance/ Basic class hierarchies that show inheritance, method overriding, and simple object models (Account, Bank, etc.). +PYQ/TNTYFIV/ Practice questions from programming contests. Contains the Colsum column‑sum calculator and the Perni binary‑number checker. +switch_case/ Programs that heavily use Java’s switch statement (date converters, menu systems, etc.). +Tip: All source files are plain Java (.java). No external dependencies or build tools required. + +⚙️ How to Compile & Run +The following one‑liner compiles every .java file in the repository and places the resulting .class files alongside their sources: + +Potentially dangerous command +Bash +Run +find . -name "*.java" | xargs javac +After compilation, run any program by specifying its fully‑qualified class name (the directory path is used as the package prefix because no explicit package statements are present): + +Potentially dangerous command +Bash +Run +### Example: run Colsum +cd PYQ/TNTYFIV +java Colsum + +### Run a for‑loop example +java for_loop.Alphabets2 +Why this stays future‑proof +• Adding new .java files automatically picks them up – no manual edits. +• The run command never changes because it relies only on the file name, not an explicit list. + +📖 Program Highlights +Folder Example What it teaches +for_loop Alphabets2.java Looping over characters. +if-else electricityBill.java Conditional logic & user input. +Inheritance Account.java, Bank.java Class hierarchy, inheritance, overriding. +switch_case D_M_Y_Converter.java Switch‑case with dates and enums. +PYQ/TNTYFIV Colsum.java 2‑D arrays, column sums, I/O. +Perni.java Recursion & binary number validation. +Feel free to open any file, modify it, recompile, and see the result instantly. + +🚀 Quick Demo: Colsum +Potentially dangerous command +Bash +Run +$ cd PYQ/TNTYFIV +$ javac Colsum.java +$ java Colsum +Enter 12 integers (row-major order): +1 2 3 4 +5 6 7 8 +9 10 11 12 +Column sums: +col 1: 15 +col 2: 18 +col 3: 21 +col 4: 24 +📜 License +This repository is released under the MIT license – feel free to copy, modify and use the code for learning or production purposes. \ No newline at end of file diff --git a/RUN_ME.java b/RUN_ME.java new file mode 100644 index 0000000..151331e --- /dev/null +++ b/RUN_ME.java @@ -0,0 +1,79 @@ +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class RUN_ME { + + static List classList = new ArrayList<>(); + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + // Step 1: Scan bin directory + File binDir = new File("bin"); + if (!binDir.exists()) { + System.out.println("bin directory not found."); + return; + } + + scanClasses(binDir, ""); + + if (classList.size() == 0) { + System.out.println("No compiled classes found."); + return; + } + + // Step 2: Display menu + while (true) { + System.out.println("\n===== PROGRAM LAUNCHER ====="); + for (int i = 0; i < classList.size(); i++) { + System.out.println((i + 1) + ". " + classList.get(i)); + } + System.out.println("0. Exit"); + + System.out.print("Enter choice: "); + int choice = sc.nextInt(); + + if (choice == 0) { + System.out.println("Exiting..."); + break; + } + + if (choice < 1 || choice > classList.size()) { + System.out.println("Invalid choice."); + continue; + } + + String className = classList.get(choice - 1); + + // Step 3: Run selected class + try { + System.out.println("\n--- Running: " + className + " ---\n"); + + Class cls = Class.forName(className); + cls.getMethod("main", String[].class) + .invoke(null, (Object) new String[]{}); + + } catch (Exception e) { + System.out.println("Error running class: " + className); + e.printStackTrace(); + } + } + + sc.close(); + } + + // Recursive scanner + static void scanClasses(File dir, String packageName) { + for (File file : dir.listFiles()) { + if (file.isDirectory()) { + scanClasses(file, packageName + file.getName() + "."); + } else if (file.getName().endsWith(".class")) { + String className = packageName + + file.getName().replace(".class", ""); + classList.add(className); + } + } + } +} \ No newline at end of file diff --git a/TODO b/TODO index f47005c..8627e9a 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,6 @@ Todo: - ☐ die + [x] die + + +based on your experience with macos and apple stuff, do u recommend me getting a macbook neo for my college stuff \ No newline at end of file diff --git a/bin/.gitattributes b/bin/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/bin/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,24 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/bin/.vscode/settings.json b/bin/.vscode/settings.json new file mode 100644 index 0000000..f41bb2a --- /dev/null +++ b/bin/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "java.project.sourcePaths": [ + "switch_case", + "if-else", + "for_loop", + "Class12Project", + "Inheritance", + "FinalRevision", + "" + ], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/bin/.zed/debug.json b/bin/.zed/debug.json new file mode 100644 index 0000000..e69de29 diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..6a77a8d --- /dev/null +++ b/bin/README.md @@ -0,0 +1,69 @@ +# 📚 Java Practice Collection +A growing library of small Java programs that illustrate core language concepts – loops, conditionals, arrays, classes, inheritance, I/O, and more. + +Why this repo? +• 100+ self‑contained examples written while learning Java (2018‑2023). +• Ready to copy‑paste, compile, run, or import into any IDE. +• All files are plain .java – no external dependencies or build tools required. + +📁 Folder Overview +Folder Typical Contents / Purpose +bin/ Compiled .class files (generated automatically by javac). No source code lives here. +Class12Project/ Exercises from a 12th‑grade curriculum (e.g., simple programs, loops, conditionals). +for_loop/ Programs that demonstrate for, while, and do‑while loops – e.g., alphabet printing, array iteration. +if-else/ Examples of conditional logic (if/else, switch) plus small utility programs (electricity bill calculator, date converter). +Inheritance/ Basic class hierarchies that show inheritance, method overriding, and simple object models (Account, Bank, etc.). +PYQ/TNTYFIV/ Practice questions from programming contests. Contains the Colsum column‑sum calculator and the Perni binary‑number checker. +switch_case/ Programs that heavily use Java’s switch statement (date converters, menu systems, etc.). +Tip: All source files are plain Java (.java). No external dependencies or build tools required. + +⚙️ How to Compile & Run +The following one‑liner compiles every .java file in the repository and places the resulting .class files alongside their sources: + +Potentially dangerous command +Bash +Run +find . -name "*.java" | xargs javac +After compilation, run any program by specifying its fully‑qualified class name (the directory path is used as the package prefix because no explicit package statements are present): + +Potentially dangerous command +Bash +Run +### Example: run Colsum +cd PYQ/TNTYFIV +java Colsum + +### Run a for‑loop example +java for_loop.Alphabets2 +Why this stays future‑proof +• Adding new .java files automatically picks them up – no manual edits. +• The run command never changes because it relies only on the file name, not an explicit list. + +📖 Program Highlights +Folder Example What it teaches +for_loop Alphabets2.java Looping over characters. +if-else electricityBill.java Conditional logic & user input. +Inheritance Account.java, Bank.java Class hierarchy, inheritance, overriding. +switch_case D_M_Y_Converter.java Switch‑case with dates and enums. +PYQ/TNTYFIV Colsum.java 2‑D arrays, column sums, I/O. +Perni.java Recursion & binary number validation. +Feel free to open any file, modify it, recompile, and see the result instantly. + +🚀 Quick Demo: Colsum +Potentially dangerous command +Bash +Run +$ cd PYQ/TNTYFIV +$ javac Colsum.java +$ java Colsum +Enter 12 integers (row-major order): +1 2 3 4 +5 6 7 8 +9 10 11 12 +Column sums: +col 1: 15 +col 2: 18 +col 3: 21 +col 4: 24 +📜 License +This repository is released under the MIT license – feel free to copy, modify and use the code for learning or production purposes. \ No newline at end of file diff --git a/bin/TODO b/bin/TODO new file mode 100644 index 0000000..8627e9a --- /dev/null +++ b/bin/TODO @@ -0,0 +1,6 @@ + +Todo: + [x] die + + +based on your experience with macos and apple stuff, do u recommend me getting a macbook neo for my college stuff \ No newline at end of file