Java

JAVA PROGRAM TO PRINT THE WORDS OF A STRING

    To  print  the  words  of  a   string  in  Java , the  best  approach  is  to   break  the  string  into   an  array  using  the  split()  method  and  then  iterate  through the  results.         public  class   PrintWords {    public  static  void   main(String  args[] ) {     String   str=”Gift  is  precious”;

JAVA PROGRAM TO PRINT THE WORDS OF A STRING Read More »

JAVA PROGRAM TO REVERSE A STRING

    Reverse  a  string   means  rearrange  the  characters  of  a  string  in  such  a  way  that  it’s  first  character  becomes  the  last  character ,  the  second  character  becomes  the  second  last, third  character  becomes  the  third  last  and  so  on .   Examples : Input :      String  str=”Giftisincredible”   Output :   

JAVA PROGRAM TO REVERSE A STRING Read More »

JAVA PROGRAM TO CHECK A STRING IS PALINDROME OR NOT

        Palindrome  String    is   a   sequence  of  characters  that   reads  the  same  forwards  and   backwards  i.e.  the  reverse  of  a  palindrome  string  is  identical  to  the  original  String.       Example:    String   s1= ” level”  Reverse  of  the  String  s1=”level”   Output:  String  s1  is  a  palindrome  string  

JAVA PROGRAM TO CHECK A STRING IS PALINDROME OR NOT Read More »

JAVA STRING CODING INTERVIEW QUESTIONS||JAVA STRING PROGRAMMING INTERVIEW QUESTIONS

  Write  a  Java  Program  to   check   the  given  String  is  Palindrome  or  not     Write  a  Java  Program  to  Reverse  a  String     Write  a  Java  Program  to  Check  if  the  given   two  Strings   are   Anagram  or  not     JAVA  PROGRAM  TO  PRINT  ALL  THE  DUPLICATE   CHARACTERS   IN  A  STRING  

JAVA STRING CODING INTERVIEW QUESTIONS||JAVA STRING PROGRAMMING INTERVIEW QUESTIONS Read More »

JAVA PROGRAM TO CHECK WHEATHER A NUMBER IS PALINDROME NUMBER OR NOT

        A  number  is  called  Palindrome  number   if  the  reverse  of  the  given  number  is  same  as   that  of  a  given  number .   Example :   Input :n= 121 Output : Reverse  of   n=121   This  Number  121  is  a  Palindrome  Number   Input:  n=885 Output : Reverse  of  n=588 This 

JAVA PROGRAM TO CHECK WHEATHER A NUMBER IS PALINDROME NUMBER OR NOT Read More »

JAVA PROGRAM TO PRINT ALL THE DUPLICATE CHARACTERS IN A STRING

    A  String  s  is  given ,  identify  all  the  characters   that  appear  more  than  once  and  print  those  characters  along  with  it’s  count  of  each.   Examples:   Input : s=”happymindhappylife”;   Output :    h 2     a 2      p  4       y  2       i   2  

JAVA PROGRAM TO PRINT ALL THE DUPLICATE CHARACTERS IN A STRING Read More »

JAVA PROGRAM TO CHECK WHEATHER A GIVEN YEAR IS LEAP YEAR OR NOT

    A  Year  is  called  Leap  Year  which   contains  366  days , which  comes   once  every  four  years .   A  Leap  year  contains  366  days  and  occur  in  every  4  years. A  century  year  (which  is  ending  with 00 )  is  a  Leap  year  only  if  it  is  divisible  by  400. A  non 

JAVA PROGRAM TO CHECK WHEATHER A GIVEN YEAR IS LEAP YEAR OR NOT Read More »

JAVA PROGRAM TO PRINT 1 TO 100 WITHOUT LOOP

          Approach:   Using  Recursion      public  class   PrintNumbers{    static  void   printNumbers(int  initial , int  last ) {        if(initial<=last){           System.out.println(initial+” ” );             printNumbers(initial+1,last);     }   }   public  static   void  main(String  args[]) {

JAVA PROGRAM TO PRINT 1 TO 100 WITHOUT LOOP Read More »

Java Program to Find the Sum of First N Odd & Even Numbers

  Numbers  which  are  divisible  by  2  are  called  even  numbers (ending  with  0 ,2,4,6,8 ),  while  numbers  that  are  not  divisible  by  2  are  called  odd  numbers (ending  with 1, 3,5,7,9 )      Example : 9    Output :   Sum  of  First  9  Even  Numbers = 2+4+6+8+10+12+14+16+18=90  Sum  of  First  9  Odd 

Java Program to Find the Sum of First N Odd & Even Numbers Read More »

JAVA PROGRAM TO CALCULATE THE SUM OF ODD NUMBERS

  Numbers  that  are   divisible  by  2  are  called  Even  numbers(ending  with 0,2,4,6,8), while  numbers  that  are  not  divisible  by  2  are  called  odd  numbers(which  are  ending  with  1,3,5,7,9)     Example:   Input: 5 Output:     Sum  of   Odd  Numbers present  from number  1  to  5 =1+3+5=9 Sum  of  Even  Numbers  present  from 

JAVA PROGRAM TO CALCULATE THE SUM OF ODD NUMBERS Read More »