diff --git a/PYQ/TNTYFIV/Colsum.java b/PYQ/TNTYFIV/Colsum.java new file mode 100644 index 0000000..7618007 --- /dev/null +++ b/PYQ/TNTYFIV/Colsum.java @@ -0,0 +1,22 @@ +public class Colsum { + int mat[][] , m , n; + Colsum(int mm, int nn) + { + m = mm; + n = nn; + mat = new int[m][n]; + } + void readArray() + { + 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