Posts

Showing posts from June, 2025

21-6-25 | Frequency of Digit and automorphic number.

Image
  //18-6-25 //Write a Java program to find frequency of each digit in a given integer. //21-6-25 //check no is automorphic or not //input n=25 //output Automorphic //as 25*25=625

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.