Posts

Showing posts from October, 2024

Convert IST to GMT

  import java . util .* ; public class TimezoneConvertor {     public static void main ( String [] args ) {                 Scanner sc = new Scanner ( System . in );         // Taking user input for minute, hour, day, month, and year         int min = sc . nextInt ();         int hour = sc . nextInt ();         int day = sc . nextInt ();         int month = sc . nextInt ();         int year = sc . nextInt ();                 // Close scanner to avoid resource leaks         sc . close ();         // Adjust hours and minutes for IST to GMT conversion         hour = hour + 5 ;         min = min + 30 ;         if ( min >= 60 ) {   ...

FizzBuzz

  import java . util .* ; public class fizzbuzz {     public static void main ( String [] args ) {         Scanner sc = new Scanner ( System . in );         System . out . println ( "Enter the number" );         int n = sc . nextInt ();         String result = ( n % 3 == 0 && n % 5 == 0 ) ? "fizzbuzz" : ( n % 5 == 0 ) ? "buzz" : ( n % 3 == 0 ) ? "fizz15" : Integer . toString ( n );         System . out . println ( result );     } }

Switch case advance usage

  import java . util .* ; public class weekday {     public static void main ( String [] args ) {         Scanner sc = new Scanner ( System . in );         System . out . println ( "Enter the number" );         int n = sc . nextInt ();         switch ( n ) {             case 1 , 2 , 3 , 4 , 5 : { System . out . println ( "week day" ); break ;}             case 6 , 7 : { System . out . println ( "week end" ); break ;}             default: System . out . println ( "Invalid Day" );                   }     }     }

Reverse of number

  import java . util .* ; class reverseofnumber {     public static void main ( String [] args ) {         Scanner sc = new Scanner ( System . in );         System . out . println ( "Enter the number" );         int k = sc . nextInt ();         int rev = 0 ;         while ( k != 0 ){             int n = k % 10 ;             rev = rev * 10 + n ;             k = k / 10 ;         }                 System . out . println ( "Reverse of number is " + rev );     } }