Posts

Showing posts from March, 2024

Java Program - print the Sum of given integer value

   Question : Write a Java program to print the sum of given integer Input: 123456 Output: 21 Steps: Step 1: Initialize the input as   int number= 123456  in main method; Step 2: Create addingIntValues()  method; Step 3: Initialize the  int reminder=0, reverseVal =0; Step 4: Iterate the while loop to reverse the number with  numbers !=0 condition Step 5: int reminder = number%10;  Step 6: reverseVal = reverseVal+reminder; Step 7:  number = number/10; Step 8: Print the output Program: public class ReverseNumber {     public static void main(String[] args) {       int number= 123456;       addingIntValues(number);   }    public static void addingIntValues(int numbers) {   int reminder =0, reverseVal=0;   while(numbers !=0) {   reminder =numbers%10;   reverseVal = reverseVal+reminder;   numbers = numbers/10;   }   System...

Java Program to print the Reversed number the given input numbers

 Question : Write a Java program to print the Reversed number the given input numbers Input: 123456 Output: 654321 Steps: Step 1: Initialize the input  in main method; Step 2: Create reverseNumber()  method; Step 3: Initialize the  int reverse =0; Step 4: Iterate the while loop with using number != 0 condition    Step 5: int reminder = number%10;  Step 6:  reverse = reverse*10+reminder; Step 7:  number = number/10; Step 8: Print the output Program: public class ReverseNumber {     public static void main(String[] args) {       int number= 123456;       reverseNumber(number);   }      public static void reverseNumber(int number){     int reverse =0; //Logic to print the reverse number     while(number != 0){       int reminder = number%10;       reverse = reverse*10+reminder;       number = number/10;   ...

Java Program - convert upper to lower and lower to upper for given string

 Question: Write a Java program to convert upper to lower and lower to upper character for given String. Input: "SeleniumTesting" Output: "sELENIUMtESTING" Steps: Step 1: Initialize the input string in main method; Step 2: Create charConversion()  method; Step 3: Initialize the StringBuffer object; Step 4: Iterate the for loop to check whether the given character is lower or upper using isLowerCase() and isUpperCase(); Step 5: Convert the character and add it into Stringbuffer using setCharAt() method; Step 6: Finally print the output public class lowerAndUpperConversion {     public static void main(String[] args) {       String name ="SeleniumTesting";      charConversion(name);   }        public static void charConversion(String name){     StringBuffer strBuff=new StringBuffer(name);     //Logic too convert the lower to upper and upper to lower     for(int i=0;i<name.length()...

Print First , Second , Third Character of Given String Using CharAt() method

Question: Write a Java program to print the First,Second and Thrid Character of given String. Input: "Selenium Testing Tool" Output: "STTeeolso" Steps: Step 1: Initialize the input string Step 2: Create findChar()  method Step 3: Split the Given String using split() method Step 4: Iterate the for loop to print the expected characters by using charAt() method Step 5: Execute the Program public class PrintFirstSecondCharOfString { public static void main(String[] args) { String input1 = "Selenium Testing Tool";   findChar(input1); } public static void findChar(String input){ String[] arrStr = input.split(" "); //Logic to print the First , second,thrid Character of  string for(int i=0;i<arrStr.length;i++){ for(int j=0;j<arrStr.length;j++){ char firstWord = arrStr[j].charAt(i); System.out.print(firstWord); } } } }  Output: STTeeolso