Java

JAVA PROGRAM TO FIND THE MAXIMUM AND MINIMUM ELEMENT IN AN ARRAY

    An  array  of  integers  arr[]  , find  the  maximum  and   minimum   elements  in  the  array.   Examples:   Input :  arr[] =[5,9,15,3,65,35];   Output :   [3 , 65 ]   Explanation :  The  minimum  element  is  3  and  the  maximum  element  is  65.       The  best  approach  to  find  the  maximum  […]

JAVA PROGRAM TO FIND THE MAXIMUM AND MINIMUM ELEMENT IN AN ARRAY Read More »

JAVA PROGRAM TO COUNT THE OCCURENCES OF EACH ELEMENT IN AN ARRAY

  To  count   the  number  of  occurence  of  each  elements  in  java, using  HashMap  is  the  most  efficient  and  standard   approach, which  runs  on  O(n)   time  complexity.       Example :     import  java.util.HashMap; import  java.util.Arrays; public  class   ElementCounter{ //Method  to  count  the   occurence  of  each  elements  in  array        

JAVA PROGRAM TO COUNT THE OCCURENCES OF EACH ELEMENT IN AN ARRAY Read More »

JAVA PROGRAM TO REMOVE DUPLICATE ELEMENTS FROM THE ARRAY

    There  are  many  approaches  to  remove  duplicate  elements  from  the  array. The  one  of  the  easiest  way  to  remove  duplicate  elements  from  the  array  is    using  HashSet,  which  automatically   remove  duplicate  elements.         Example :      import    java.util.*; public  class   RemoveDuplicates{  //Function  to  remove  duplicate elements  from   array

JAVA PROGRAM TO REMOVE DUPLICATE ELEMENTS FROM THE ARRAY Read More »

JAVA ARRAY CODING AND PROGRAMMING INTERVIEW QUESTIONS AND ANSWERS

        Write  a  Java  Program  to  Reverse  an  Array     Write  a  Java  Program  to  Remove  Duplicate  Elements  From  the  Array     Java  Program  to  count  the  occurences  of  each  element  in  an  array.     Write  a  Java  Program  to  find  the  Second  Largest  Element  In  an  Array  

JAVA ARRAY CODING AND PROGRAMMING INTERVIEW QUESTIONS AND ANSWERS Read More »

JAVA PROGRAM TO REVERSE THE WORDS OF A STRING

  In  this   approach   we  are  using  split()  method  to  reverse  the  words  of  a  string.       import  java.util.*;   public  class   ReverseWords {         public  static  void  main(String  args[] ) {         Scanner  sc=new   Scanner(System.in);         System.out.println(“Enter  a  String”);        

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

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 »