Posts

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." );   }

Calculate the Nth term - Hacker Rank Solution .

Image
  Objective This challenge will help you learn the concept of recursion. A function that calls itself is known as a recursive function. The C programming language supports recursion. But while using recursion, one needs to be careful to define an exit condition from the function, otherwise it will go into an infinite loop. To prevent infinite recursion,  statement (or similar approach) can be used where one branch makes the recursive call and other doesn't. void recurse() {     .....     recurse()  //recursive call     ..... } int main() {     .....     recurse(); //function call     ..... }

Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float).Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members. If an exception is caught, replace all the data member values with zero values.

Class:-SE Computer OOP & CG Practical Title:-Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float).Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members. If an exception is caught, replace all the data member values with zero values.