Skip to main content

Posts

Showing posts with the label strings

Reverse String Wordwise

Question:  Reverse the given string word wise. That is, the last word in given string should come at 1st place, last second word at 2nd place and so on. Individual words should remain as it is. Input format : String in a single line Output format : Word wise reversed string in a single line Constraints : 0 <= |S| <= 10^7 where |S| represents the length of string, S. Sample Input 1: Welcome to Coding Ninjas Sample Output 1: Ninjas Coding to Welcome Ans:  package learningJava ; import java . util .*; /** * This program demonstrates a function to reverse words in a given string. * It takes a string as input and reverses the order of words in the string. */ public class regPract { /** * Reverses the order of words in a given string. * * @param end The ending index of the input string. * @param start The starting index for extracting a word. * @param j An index variable used in loops. * @param input The input string to rever...

String Palindrome in JAVA

Question:  Given a string, determine if it is a palindrome, considering only alphanumeric characters. Palindrome A palindrome is a word, number, phrase, or other sequences of characters which read the same backwards and forwards.   package learningJava ; import java . util .*; public class regPract { /* Find the maximum and minimum element in an array */ public static boolean checkPalindrome ( String str , String rev ) { if ( str . equals ( rev )) { return true ; } return false ; } public static void main ( String [] args ) { Scanner scan = new Scanner ( System . in ) ; System . out . println ( "Enter String:" ) ; String str = scan . nextLine () ; String rev = "" ; for ( int i = str . length () - 1 ; i >= 0 ; i -- ) { rev = rev + str . charAt ( i ) ; } checkPalindrome ( str , rev ) ; boolean isPalindrome = checkPalindrome ( str , rev ) ; ...

Strings In Java

Question: What is String in JAVA ? Ans: Java me, "String" ek data type hota hai jo text ko represent karta hai. String ek sequence of characters hoti hai, jaise ki alphabets, numbers, symbols, aur special characters. Java me, String class predefined hoti hai, aur aap iska istemal karke text data ko store, manipulate, aur access kar sakte hain. Strings are non Primitive Data Type. Question: What is .length(); ? Ans: this is to check length of a String . Question: Different between single quote and double quote in String . Ans: Single quote ' ' ['D'] is basically used to store character but double quote is used to store " " ["Divyanshu"] a string basically sequence of character .  Question: How to add, concat a string ? Ans : There is two way to concat or add a string               1) first is to use  Addition (+) arithemetic operator               2) .concat package learningJava ; import java . ut...