😍 Day 17 of My Java Learning Journey – Finding Odd or Even Numbers 🔢 . Hey everyone 👋 . Today, I explored a simple but important concept 💯 ~ how to check whether numbers are odd or even in Java using conditional statements (if-else). . Here’s the code I practiced today: 👇 --------------------------------------code start-------------------------------------- public class FindOddOrEvenNumberDemo { public static void main(String[] args) { int c = 32; int d = 21; if (c % 2 == 0 && d % 2 == 0) { System.out.println("c & d both are even number"); } else if (c % 2 != 0 && d % 2 != 0) { System.out.println("c & d both are odd number"); } else if (c % 2 == 0) { System.out.println("c is even number and d is odd number"); } else { System.out.println("c is odd number and d is even number"); } } } ------------------------------------code output------------------------------------ c is even number and d is odd number ------------------------------------code end--------------------------------------- 💡 Explanation: The expression number % 2 gives the remainder when dividing the number by 2. If the remainder is 0, the number is even. If the remainder is not 0, the number is odd. . I used multiple if-else conditions to check all possibilities: Both numbers are even. Both numbers are odd. One is even and the other is odd. . 👉 In this example, c = 32 (even) and d = 21 (odd), so the output will be: ~ c is even number and d is odd number. . Building these logic-based programs helps strengthen my understanding of control flow and conditions in Java, which are essential for solving real-world coding problems. . #Java #Coding #LearnJava #100DaysOfCode #DevOps #JavaLearningJourney #Day16 #Programming #CodeWithYuvi #LogicBuilding .
Yuvraj Singh Kushwah’s Post
More Relevant Posts
-
🎯 Day 15 of My Java Learning Journey 🎯 . Hey everyone! 👋 .. Today I explored Selection Statements again — but this time, I focused on finding the smallest number among four values using if-else if ladder in Java. Here’s the code I wrote 👇 --------------------------------------code start--------------------------------------- public class FindSmallerNumberDemo2 { public static void main(String[] args) { int l = 1; int m = 2; int n = 3; int o = 4; if (l < m && l < n && l < o) { System.out.println("l is smaller"); } else if (m < o && m < n && m < l) { System.out.println("m is smaller"); } else if (o < n && o < m && o < l) { System.out.println("o is smaller"); } else { System.out.println("n is smaller"); } } } --------------------------------------code output---------------------------------- l is smaller number -------------------------------------code end--------------------------------------- . 💡 Explanation: I’ve declared four integer variables — l, m, n, and o. The if statement checks multiple conditions using logical AND (&&) to make sure one number is smaller than all others. . If the first condition fails, the program moves to the next else if condition. Finally, if none of the earlier conditions are true, the else block executes — meaning the last variable n is the smallest. . 🧠 This program is a simple way to understand how comparison and logical operators work together in decision-making statements. In the next few posts, I’ll share more concepts related to selection and looping statements in Java 🚀 . #Day15 #JavaLearningJourney #100DaysOfCode #LearnJava #Programming #DevOps #Coding #JavaBeginners #SelectionStatement #IfElseInJava .
To view or add a comment, sign in
-
-
🌟 Day 14 of My Java Learning Journey 🔥 💯 Hey everyone! 👋 ~ Today’s topic was all about decision-making in Java — how a program chooses which path to follow based on given conditions. 💡 . I explored how to find the greatest number among multiple values using nested if-else statements, one of the core parts of selection statements in Java. 💻 Here’s the code I worked on today: 👇 -------------------------------------code start-------------------------------------- public class FindGreaterNumberDemo2 { public static void main(String[] args) { int p = 11; int q = 22; int r = 33; int s = 44; if (p > r && p > s && p > q) { System.out.println("p is greater number "); } else if (q > s && q > p && q > r) { System.out.println("q is greater number"); } else if (r > p && r > s && r > q) { System.out.println("r is greater number"); } else { System.out.println("s is greater number"); } } } -------------------------------------code output------------------------------------ s is greater number ---------------------------------------code end-------------------------------------- . 🔍 Explanation: We have four integer variables: p, q, r, and s. Using an if-else-if ladder, we compare each number with the others using the logical AND (&&) operator. The first condition that turns out true will print which number is the greatest. If none of them match, the else block executes, showing that s is the greatest. . 💡 Key Takeaway: Selection statements like if, else if, and else help control the program’s logic — deciding what happens next depending on the condition. . 🚀 What’s next? In the upcoming posts, I’ll share many more real-world examples related to selection statements, so we can deeply understand how decision-making works in Java programs. Stay tuned — it’s gonna get crazy cool and more practical! 💻🔥 . #Java #100DaysOfCode #Day14 #JavaLearningJourney #FlowControl #IfElse #SelectionStatements #DevOps #Programming #CodingJourney #LearnJava #TechLearner #CodeNewbie .
To view or add a comment, sign in
-
-
🚀 Java Learning Journey – Day 22 🔥 Understanding Switch Case with Expressions (Java) Today I explored how switch-case works when we use expressions inside the case labels. ~ In Java, expressions like (0+1) or (1+2) get evaluated first, and then matched with the switch variable. The interesting part is fall-through, which happens when we don’t use a break statement. This helps in understanding how multiple cases can run together. ✅ Here’s the code I practiced today: -------------------------------------code start------------------------------------ public class SwitchDemo2 { public static void main(String[] args) { int x = 0; //x=0 (E) | x=1 (A,B) | x=2 (B) | x=3 (C,D,E) | x=4 (D,E) | x=5 (E) switch (x) { case (0+1): System.out.println("A"); case (1+1): System.out.println("B"); break; case (1+2): System.out.println("C"); case (2+2): System.out.println("D"); default: System.out.println("E"); } } } ----------------------------------code output------------------------------------ E -------------------------------------code end------------------------------------ 🧠 Key Takeaways case expressions are evaluated before matching. Without break, execution continues to the next case (fall-through). Helps in understanding how switch-case flows internally. 🌱 Personal Note: I’m continuously learning Java and exploring DevOps tools and practices to build a strong foundation for full-stack and automation development. If you like my daily progress posts, please support with a like, comment, or share ~ it truly motivates me to keep learning and sharing. 🙌 I’m also looking for internship opportunities in Java development or DevOps to apply my skills in real-world projects, learn from professionals, and grow further. If you know of any such opportunities or can guide me, I’d really appreciate your help 🙏 #JavaLearningJourney #day22 #Java #Programming #LearningInPublic #SwitchCase #JavaBeginners #CodeNewbie #FallThrough #DeveloperJourney #DevOps #TechJourney #LearningEveryday
To view or add a comment, sign in
-
-
🌟 Day 7 of My Java Learning Journey ~> Understanding == vs .equals() in Java 🔥 Hey connections 👋 Today I explored one of the most commonly confusing topics in Java — the difference between == and .equals(). Let’s break it down simply 👇 💡 == Operator Used to compare memory references (i.e., whether two variables point to the same object in memory). Works perfectly for primitive data types like int, char, boolean, etc. But when used with objects (like String), it only checks if both references point to the same object, not if their values are equal. 🧩 Example: -------------------------------------code start---------------------------------------- String s1 = new String("Java"); String s2 = new String("Java"); System.out.println(s1 == s2); // false (different memory locations) System.out.println(s1.equals(s2)); // true (same value) --------------------------------------code end--------------------------------------- 💬 .equals() Method Comes from the Object class. Used to compare the actual content (values) of two objects. In most Java classes (like String, Integer, etc.), it’s overridden to check value equality. 🧩 Example: ----------------------------------code start------------------------------------------- String name1 = "Yuvi"; String name2 = "Yuvi"; System.out.println(name1 == name2); // true (same memory due to String pool) System.out.println(name1.equals(name2)); // true (same value) ----------------------------------code end------------------------------------------- 🚀 Quick Summary ~ Comparison TypeWorks OnChecks==Primitives ~ Object referencesMemory location.equals()ObjectsActual values/content ✨ Remember: Use == for primitive data types Use .equals() for comparing object values 💭 This small concept makes a big difference when working with strings, collections, and custom objects. #Java #Coding #LearningJourney #JavaDeveloper #OOPs #Programming #100DaysOfCode #DevOps #JavaLearning #SoftwareDevelopment #LinkedInLearning
To view or add a comment, sign in
-
-
🚀 Day 20 of My Java Learning Journey ~ Switch Statement with Break 💯 . Hey everyone 👋 Today, I learned about the switch statement in Java ~ a control flow statement that helps us choose one action out of many based on a given value. Here’s the program I practiced 👇 --------------------------------------code start--------------------------------------- public class SwitchDemoWithBreak { public static void main(String[] args) { int x = 2; switch (x) { case 1: System.out.println("Today is Monday"); break; case 2: System.out.println("Today is Tuesday"); break; case 3: System.out.println("Today is Wednesday"); break; case 4: System.out.println("Today is Thursday"); break; case 5: System.out.println("Today is Friday"); break; case 6: System.out.println("Today is Saturday"); break; case 7: System.out.println("Today is Sunday"); break; default: System.out.println("You have entered the number out of range"); } } } -----------------------------------code output--------------------------------------- Today is Tuesday --------------------------------------code end--------------------------------------- 🧠 Explanation: The switch statement checks the value of x and executes the matching case. Each case represents a possible value of x. The break statement prevents execution from continuing into the next case. The default block runs when no case matches. 👉 In this example, since x = 2, it prints: “Today is Tuesday” ✅ 🌱 Personal Note: I’m continuously learning Java and exploring DevOps tools and practices to build a strong foundation for full-stack and automation development. If you like my daily progress posts, please support with a like, comment, or share ~ it truly motivates me to keep learning and sharing. 🙌 I’m also looking for internship opportunities in Java development or DevOps to apply my skills in real-world projects, learn from professionals, and grow further. If you know of any such opportunities or can guide me, I’d really appreciate your help 🙏 . #Java #LearningJourney #Day20 #CodingInPublic #SwitchCase #BreakStatement #JavaDeveloper #DevOps #Internship #CareerGrowth #CodeWithYuvi ..... ... .
To view or add a comment, sign in
-
-
Java with DSA Challenge Day 5 Challenge Problem: Check Prime Number Today’s challenge was to determine whether a given integer n is a prime number or not. A prime number is a number greater than 1 that is divisible only by 1 and itself. Example: Input: n = 17 Output: True Explanation: 17 is divisible only by 1 and 17. This problem is a fundamental concept in number theory and serves as a great way to understand time complexity optimization in algorithms. Code Snippet // User function Template for Java class Solution { public static boolean prime(int n) { // 0 and 1 are not prime numbers if (n <= 1) return false; // 2 and 3 are prime numbers if (n <= 3) return true; // Eliminate multiples of 2 and 3 if (n % 2 == 0 || n % 3 == 0) return false; // Check divisibility up to √n using 6k ± 1 rule for (int i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; // number is prime } public static void main(String[] args) { int n1 = 17, n2 = 56; System.out.println(n1 + " is prime? " + prime(n1)); // true System.out.println(n2 + " is prime? " + prime(n2)); // false } } Code Explanation 1.Base Case Handling Numbers ≤ 1 are not prime, so we return false. 2. Small Prime Numbers 2 and 3 are prime by definition, so we return true. 3. Eliminate Multiples of 2 and 3 Any number divisible by 2 or 3 (except 2 and 3 themselves) cannot be prime. 4. Using the 6k ± 1 Rule All primes greater than 3 can be written as 6k ± 1. So, instead of checking every number, we only check divisibility for numbers of this form up to √n. This reduces unnecessary iterations and makes the code much faster. 5.Return True If no divisors are found, the number is prime. Complexity Time Complexity: O(√n) Space Complexity: O(1) Output 17 is prime? true 56 is prime? false Reflection This problem shows how even a simple concept like checking prime numbers can be optimized using mathematical insights like the 6k ± 1 rule. #Java #DSA #100DaysOfCode #CodingChallenge #ProblemSolving #GeeksforGeeks #Algorithms #LearnToCode #JavaDeveloper #SoftwareEngineering #DataStructures #Developer
To view or add a comment, sign in
-
-
🚀 Java Learning Series — Day 5 Topic: Introduction to Threads in Java ☕️ A Thread is a sort of mini-worker within your program that performs tasks independently. Instead of doing everything one-by-one, threads let Java do multiple things at the same time. ------------------------------------- Quick Notes: • Thread → a lightweight process running independently • Multithreading: Running multiple threads together • Main thread → the one that starts automatically when program runs ------------------------------------- Simple Code: class MyWork extends Thread { public void run() { System.out.println("Thread is working: " + Thread.currentThread().getName()); } public static void main(String[] args) { MyWork t1 = new MyWork(); MyWork t2 = new MyWork(); t1.start(); t2.start(); System.out.println("Main thread continues…"); } } ------------------------------------- ⚙️ Real-World Places You See Threads: 1. You scroll Instagram while videos load in the background 2. WhatsApp: Sending message + loading DP + encryption — all parallel 3. Music App: audio playing + lyrics sync + animation ✨ 4. Browser: multiple tabs loading at once 5. PUBG/BGMI: render graphics + network updates + input controls ------------------------------------- Interview-Quick Questions: 1️⃣ What is a Thread in Java? 2️⃣ What is the difference between Process and Thread? 3️⃣ What is main thread? 4️⃣ Why do we use start() instead of calling run() directly? 5️⃣ What is Multithreading and its benefits? ------------------------- #Java #Threads #LearnWithRahulVarma #100DaysOfJava #CodingJourney #MultiThreading #SoftwareEngineer #LearningNeverStops #JavaDeveloper
To view or add a comment, sign in
-
-
🔥 Day 19 of My Java Learning Journey 🚀 Today, I practiced an interesting topic — Login Simulation in Java 💻 Here’s the code I wrote 👇 ---------------------------------------code start--------------------------------- public class LoginSimulationDemo { public static void main(String[] args) { String userName = "yuviii@321"; // Expected username int password = 32143; // Expected password if (userName.equals("yuviii@321") && password == 32143) { System.out.println("Login Successfully 🥳😍"); } else if (!userName.equals("yuviii@321") && password != 32143) { System.out.println("Both Credentials are Invalid (❌)"); } else if (userName.equals("yuviii@321")) { System.out.println("userName is valid (✔) & password is invalid (❌)"); } else { System.out.println("userName is invalid (❌) & password is valid (✔)"); } } } --------------------------------------code output--------------------------------- Login Successfully 🥳😍 ---------------------------------------code end----------------------------------- 🧠 Explanation: In this program, I tried to simulate how a basic login system works. 1️⃣ First, I declared two variables: userName (String) password (int) These represent the credentials that a user might enter. 2️⃣ Then I used if-else conditions to check four possible scenarios: ✅ Case 1: If both userName and password match the expected values → login successful. ❌ Case 2: If both are wrong → print “Both Credentials are Invalid.” ⚠ Case 3: If only the username is correct → show that password is wrong. ⚠ Case 4: If only the password is correct → show that username is wrong. This is a simple but effective way to understand how conditional statements and logical operators (&&, !=) work together in real-world programs like login forms. 3️⃣ The method equals() is used to compare String values — because using == only compares memory locations, not the actual text inside the string. By writing this, I learned how logical conditions can control the program’s behavior and make decisions dynamically — which is a very important concept in Java programming! 💪 💬 What do you think about this login simulation idea? If you found it helpful ~ 👉 Don’t forget to Like ❤️, Comment 💬, and Share 🔁 this post to support my Java learning journey! #JavaLearning #Day19 #JavaJourney #CodingInJava #ConditionalStatements #IfElse #LoginSystem #ProgrammingBasics #CodeWithYuvi #DevOps #100DaysOfCode
To view or add a comment, sign in
-
-
As part of my #JavaLearningSeries, I explored some of the most repeated and crucial topics that every Java beginner must master — Array Length, Jagged Arrays, and Indexing. These concepts may seem simple, but they’re the foundation for writing efficient, professional, and error-free Java code 👇 🔹 1️⃣ The Power of .length This concept was emphasized throughout — it’s one of the most must-know topics in Java arrays. 💡 .length is a built-in variable that tells you the array’s size — used to make flexible and dynamic loops. ✅ Never hardcode numbers like i < 5; always use .length instead. for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } 🔹 2️⃣ Jagged Arrays — Real World, Irregular Data In real-world data, everything isn’t regular. One classroom may have 3 students, another 5 — this is jagged data. Jagged arrays allow us to store this irregular data efficiently without wasting memory. 💡 Regular arrays = all rows same size 💡 Jagged arrays = each row can have different sizes int[][] a = new int[2][]; // 2 classrooms a[0] = new int[3]; // Class 1 → 3 students a[1] = new int[5]; // Class 2 → 5 students 🧠 Each row (classroom) can be defined separately — perfect for dynamic and realistic data storage. 🔹 3️⃣ Index Starts from 0 — But the Real World Starts from 1 😉 A very interesting and relatable concept! For Java developers, 0 means 1. for (int i = 0; i < a.length; i++) { System.out.println("Student " + (i + 1) + ": " + a[i]); } ✅ Start from 0 in loops ✅ Add +1 when printing (for user clarity) 🔹 4️⃣ Complete Example – Jagged Array Input & Output int[][] a = new int[2][]; a[0] = new int[3]; a[1] = new int[5]; Scanner scan = new Scanner(System.in); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.print("Enter age of class " + (i + 1) + " student " + (j + 1) + ": "); a[i][j] = scan.nextInt(); } } System.out.println("The ages are:"); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.print(a[i][j] + " "); } System.out.println(); } 🎯 This example combines .length, indexing, and jagged array creation — all in one program. 💬 Key Takeaways ✅ .length makes your code dynamic and professional ✅ Jagged arrays save memory and handle real-world irregular data ✅ Always start counting from 0 (and print using +1 for clarity) 📚 Every session strengthens my understanding of how Java handles data in memory. #Java #LearningJourney #ProgrammingFundamentals #SoftwareDevelopment #ContinuousLearning #TechCareers #CareerGrowth #CodingCommunity #StudentDeveloper #RecruitersOnLinkedIn #ArraysInJava #JavaProgramming #Upskilling #TechLearning #WomenInTech #LearningSeries #JaggedArrays #JavaBasics #TapAcademy
To view or add a comment, sign in
-
-
🚀 Day 21 of My Java Learning Journey ~ Switch Statement Without Break – Fall-Through Behavior Explained 💡 . Hey everyone 👋 Today, I learned how the switch statement behaves when we don’t use the break keyword. This is an important Java concept called fall-through, where execution continues into the next cases until the switch ends. Here’s the program I practiced 👇 --------------------------------------code start--------------------------------------- public class SwitchDemoWithoutBreak { public static void main(String[] args) { int m = 9; switch (m) { case 1: System.out.println("the month is january"); case 2: System.out.println("the month is February"); case 3: System.out.println("the month is March"); case 4: System.out.println("the month is April"); case 5: System.out.println("the month is May"); case 6: System.out.println("the month is June"); case 7: System.out.println("the month is July"); case 8: System.out.println("the month is August"); case 9: System.out.println("the month is September"); case 10: System.out.println("the month is October"); case 11: System.out.println("the month is November"); case 12: System.out.println("the month is December"); default: System.out.println("You have entered the number out of range"); } } } -----------------------------------code output--------------------------------------- the month is September the month is October the month is November the month is December You have entered the number out of range --------------------------------------code end--------------------------------------- 🧠 Explanation: The switch statement checks the value of m. Since there is no break statement in any case, Java continues executing all cases from the matching case until the end. This behavior is known as fall-through. Since m = 9, the program starts printing from case 9 all the way to default. 👉 This helps you understand why break statements are important when you want to stop execution after a specific matched case. 🌱 Personal Note: I’m learning Java consistently every day and improving my understanding of core concepts. Along with Java, I’m also exploring DevOps tools to strengthen my development and automation skills. If you find my daily learning posts helpful, please support with a like, comment, or share — it really motivates me to keep going! 🙌 I’m also actively looking for internship opportunities in Java development or DevOps. If you know of any openings or can guide me, I’d truly appreciate your help 🙏 . hashtag#Java hashtag#LearningJourney hashtag#Day21 hashtag#SwitchCase hashtag#FallThrough hashtag#JavaDeveloper hashtag#CodingInPublic hashtag#DevOps hashtag#Internship hashtag#CareerGrowth hashtag#CodeWithYuvi ....... ...
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development