Skip to main content

Posts

Java Program To Find Out The Maximum Times Repeated Number From An Array

  Java Program To Find Out The Maximum Times Repeated Number From An Array ================================================================================= import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class MaxRepeatedNumber {     public static void main ( String [] args ) {         // Use Scanner Class Object To retrieve elements from the console         Scanner sc = new Scanner ( System . in );         System . out . println ( "Enter the number of elements of an Array:" );         Integer number = sc . nextInt ();         int arr [] = new int [ number ];         // Adding elements into an array one by one         for ( int i = 0 ; i < number ; i ++) {             arr [ i ] = sc . nextInt ();         }   ...

Java Program To Find Out Character Occurances In A String

 Java Program To Find Out Character Occurences In A String ======================================================================== import java . util . HashMap ; import java . util . Map ; public class OccuranceOfCharInString {     public static void main ( String [] args ) {         // Java Program To Count the Occurnaces Of Character In A String.         String str = "WelcomeToJava" ;         // create HashMap Containing char as key and occurance as a value         HashMap < Character , Integer > charMap = new HashMap < Character , Integer >();         // converting given String to An Array         char ch [] = str . toCharArray ();         // Loop for checking each character of str Array         for ( char c : ch ) {             if ( charMap . contains...

Java Program To Write Data Into The Text File

 Java Program To Write Data Into The  Text File ========================================================================== Java Program To Write Data Into The  Text File ====================================================================== import java . io . BufferedWriter ; import java . io . FileWriter ; import java . io . IOException ; public class WriteDataIntoTextFile {         public static void main ( String [] args ) throws IOException {                 FileWriter fw = new FileWriter ( "C: \\ Users \\ lenovo \\ Desktop \\ test.txt" );         BufferedWriter bw = new BufferedWriter ( fw );         bw . write ( "Selenium With Java" );         bw . write ( "Selenium With Python" );         bw . write ( "Selenium with C#" );         System . out . println ( "finished !!!" );     ...

Java Program To Read Data From The Text File

Java Program To Read Data From The Text File  ============================================================= How To Read Data From The Text File: import java . io . BufferedReader ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . IOException ; public class ReadDataFromTextFile {     public static void main ( String [] args ) throws FileNotFoundException , IOException {         FileReader fr = new FileReader ( "C: \\ Users \\ lenovo \\ Desktop \\ test.txt" );         // Read the File From the Location Present inside the PC / Disc.         BufferedReader br = new BufferedReader ( fr );         String str ;         while (( str = br . readLine ()) != null ) {             System . out . println ( str );         }         br . close ();   ...

Java Program To Reverse Each Word In A String

 Java Program To Reverse Each Word In A String ======================================================================== public class ReverseEachWordInAString {     public static void main ( String [] args ) {         String str = "Welcome To Java" ;         String words [] = str . split ( " " );         String reverseString = "" ;         for ( String w : words ) {             String reverseWord = "" ;             for ( int i = w . length () - 1 ; i >= 0 ; i --) {                 reverseWord = reverseWord + w . charAt ( i );             }             reverseString = reverseString + reverseWord + " " ;         }         System . out . println ( reverseString );   ...

Java Program To Count Words In A String

Java Program To Count Words In A String ========================================================================== import java . util . Scanner ; public class CountWordsInString {     public static void main ( String [] args ) {         Scanner sc = new Scanner ( System . in );         System . out . println ( "Enter the String:" );         String str = sc . nextLine ();         int count = 1 ;         for ( int i = 0 ; i < str . length () - 1 ; i ++) {             if (( str . charAt ( i ) == ' ' ) && ( str . charAt ( i + 1 ) != ' ' )) {                 count ++;             }         }         System . out . println ( "Number Of Words In A String:" + count );     } } Output: ============== Enter the...

Java Program To Remove White Spaces In A String

 Java Program To Remove White Spaces In A String ===================================================================== public class RemoveWhiteSpaces {     public static void main ( String [] args ) {         String str = "Java Programming Selenium Automation" ;         str = str . replaceAll ( " \\ s" , "" );         // //s --> This represents the single whitespace character in a String.         System . out . println ( "After removing the whitespaces in a String:" + str );     } } output: ======= After removing the whitespaces in a String:JavaProgrammingSeleniumAutomation