Posts

17- 6-25 | Fibonacci Series | While(true) is infinite loop untill we break. | InputMismatchException in scanner object | sc.next in catch block.

Image
  //17-6-25 //Generate Fibonacci series. 0,1, 1, 2, 3, 5,8 ..... k. where k < n . n is entered by user while(true) literally means "loop forever". The condition inside the while loop ( true ) is always true, so ordinarily, this loop would never terminate on its own. It's an infinite loop . we use break statement to come out of the loop. using a try-catch block around the Scanner.nextInt() InputMismatchException means the Scanner object's nextInt() method (or nextDouble() , nextLong() , etc.) was expecting to read an integer (or a double, long, etc.), but the user typed something that couldn't be parsed as that type . we use sc.next() in the catch block because : clear the buffer and prevent infinite loops . ✅ What sc.next(); does: It consumes (reads and discards) the invalid input token from the buffer, allowing the loop to prompt the user again with a clean buffer.

Streak ended - 28-05-2025 - Problems solved so far. _ Posting just important ones.

Image
Important problems solved so far : Sum of all digits until single digit. //Reverse the number.

Day 4 - 27-05-2025 - Solving Assignment Questions - Encapsulation Example, AccessModifier example,

Image
// Give the real time example of encapsulation with code. //Create a class Student with 4 variables called as rollNo, admissionNo, age, //courseId.Each of the variables should have one of the access modifier - //public, protected, no-access-modifier and private.Add 4 methods in the //class – public, method doPublic, no access modifier method doDefault, //protected method doProtected, private method doPrivate. //a. In main method outside the class but in same package – create object of //type Student. //b. Try to access rollno outside the class. //c. Try to access age outside the package. //d. Also try to access private methods outside the class and protected //methods outside the package. Learnings : Modifier Same Class Same Package Subclass (same pkg) Subclass (other pkg) Other Class (other pkg) public ✅ ✅ ✅ ✅ ✅ protected ✅ ✅ ✅ ✅ (via subclass) ❌ (default) ✅ ✅ ✅ ❌ ❌ private ✅ ❌ ❌ ❌ ❌

Day 3 - 26-05-2025 - Solved 3 Assignment Questions : Account (insert(), deposit(), withdraw(),display()) , arithmetic operation(+-*/), Employee (getter setter).

Image
  //Write java Program for arithmetic operation for each operation write //separate Method using parameter passing and return type. //Create one class Employee (id , name, salary) with private access modifier //and create getter and setter.     

Day 2 - 25th May 2025 - Still Solving Assignment problems from TQ d3 assignment.

Image
   //Create a class Account containing following methods - //insert () to insert account data //display () to display account information //deposit () to deposit amount //withdraw () to withdraw amount //check_balance() to check balance Didnt solve much of the problems today.

DAY 1 - 24th May 2025

Image
JAVA QUESTIONS AND THEORY PRACTICE  //create class Student and create 2 objects of Student using new keyword //Now id, name in student class. assign value to id, name there Itself and in //main method print values then change value of instance variables and again //print the values (Observe you cannot access id directly without creating //object) //Create getId() method in Student class. call getId() method from //displayData method so that you know that one method can be called from //another method. Return id from getId() method and set that id to the //instance variable in displayData method. //Add display method inside Student class change values of id, name in that //method & also print the changed values in same method. Call display //method from main method. //24th May 2025 //Write a program to copy values of one object into another by assigning the //values of one object into another.