Posts

Showing posts from August, 2024

Java Program To Find Last Digit Of a Number is Even Or Odd.

Image
  Find Last Digit Of  Number is Even Or Odd. import java.util.*; class FirEvenOdd {     public static void main( String [] args)     {         Scanner sc= new Scanner(System.in);         System.out.println( "Enter a number" );         int n=sc.nextInt();         while (n>= 10 )         {             n=n% 10 ;                     }         if (n% 2 == 0 )         {             System.out.println(n+ " is even" );         }         else         {             System.out.println(n+ " is odd" );         }     } }

Java Program For Find Addition Of First and Last Digit Of Number.

Image
  Addition Of First and Last Digit Of Number. // Java Program to find first and last and addition of it. import java.util.*; import java.lang.*; class FirLastAdd{     // Find the first digit     public static int firstDigit( int n)     {         // Remove last digit from number         // till only one digit is left         while (n >= 10 )             n /= 10 ;             // return the first digit         return n;     }     // Find the last digit     public static int lastDigit( int n)     {         // return the last digit         return (n % 10 );     }         // driver function     public static void main( String argc[])     {         Scanner sc= new Scanner(System.in);         System.out.println( "Enter a number" );         int n=sc.nextInt();         System.out.println(firstDigit(n) + + + lastDigit(n));     } }  

Java - Happy Number Program.

Image
   Happy Number Program. import java.util.Scanner; class  HappyNum {     public static void main( String [] args)     {         Scanner sc= new Scanner(System.in);         System.out.println( "Enter Number" );         int num=sc.nextInt();         int rem= 0 ;         int sqr= 0 ;         while (num> 9 )         {             int sum= 0 ;             while (num> 0 )             {                 rem=num% 10 ;                 sqr=rem*rem;                 sum=sum+sqr;                 num=num/ 10 ;             }             num=sum;         }         if (num== 1 )         {             System.out.println( "Happy Number" );         }         else         {             System.out.println( "Not Happy" );         }     } }  

Java Program for print the TABLE of a number.

Image
 JAVA CODE - TABLE OF A NUMBER: import java.util. Scanner ; class TableOfNumber {     public static void main ( String [] args )     {         Scanner sc = new Scanner ( System . in );         System . out . println ( "Enter a Number" );         int num = sc . nextInt ();         if ( num > 0 )         {             for ( int i = 1 ; i <= 10 ; i ++ )             {                 System . out . println ( num + " * " + i + " = " + num * i );             }         }         else         {             System . out . println ( "Wrong Number" );         }     } }

JAVA- Tech Number Program.

Easy way to solve TECH NUMBER program.   import java . util . Scanner ;   public class TechNumber {   public static void main ( String args [])   {   int n , num , firstHalf , secondHalf , digits = 0 , squareOfSum = 0 ;   Scanner sc = new Scanner ( System . in );   System . out . print ( "Enter a number to check: " ); n = sc . nextInt ();   num = n ;     while ( num > 0 )   {         digits ++ ;   num = num / 10 ;   }     if ( digits % 2 == 0 )   {   num = n ;   firstHalf = num % ( int ) Math . pow ( 10 , digits / 2 ); secondHalf = num / ( int ) Math . pow ( 10 , digits / 2 );   squareOfSum = ( firstHalf + secondHalf ) * ( firstHalf + secondHalf );   if ( n == squareOfSum )   {   System . out . println ( n + " is a tech number." );   }   else   {   System . out . println ( n + " is not a tech number." );   }   }   else   {   System . out . println ( n + " is not a tech number." );   }