Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners A Program To Reverse Words In String in Java

Have Programming Question? Ask it here!
 
 
 


Yash Agarwal
A Program To Reverse Words In String in Java
1 Answer(s)      a year and 9 months ago
Posted in : Java Beginners


A Program To Reverse Words In String in Java
for example:
Input:- Computer Software
Output :- Software Computer
without using split() , StringTokenizer function or any extra ordinary fuction only by using simple loop , if else , and for loop.
Please Tell Me This Program.


Advertisement
View Answers

November 28, 2012 at 2:24 PM


Here is an example that reverse the words in a sentence.

public class ReverseWordsUsingLoops{

    public char[] reverseWords(char[] ch){
        int i;
        int index = 0; 
        for(i=0;i<=ch.length;i++){
            if(i==ch.length){
                reverse(ch,index,i-1);
            }
            else if(ch[i]==' '){
                reverse(ch,index,i-1);
                index = i+1;
            }
        }
        reverse(ch,0,i-2);
        return ch;
    }
    public char[] reverse(char[] ch,int start, int end){
        char temp;
        while(start<end){
        temp = ch[start];
        ch[start++]=ch[end];
        ch[end--]=temp;
        }
        return ch;
    }
    public static void main(String args[]){
        ReverseWordsUsingLoops rw = new ReverseWordsUsingLoops();
        String s = "Conputer Software";
        char[] ch = s.toCharArray();
        System.out.println(rw.reverseWords(ch));
    }
}


Related Tutorials/Questions & Answers:
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
Advertisements
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java
A Program To Reverse Words In String in Java  A Program To Reverse Words In String in Java for example: Input:- Computer Software Output... Tell Me This Program.  Here is an example that reverse the words
Java Reverse words of the String
Reverse words of the String Java Programming In this section, we are going to reverse the words of the string. For this, we have allowed the user to enter... the string: java is a programming language Reversed Words: language
Java reverse words in a string using only loops
Java reverse words in a string using only loops In this tutorial, you will learn how to reverse words in a string without using any inbuilt methods like...;=c.length;i++) { if(i==c.length) { reverse(c,word_start_index,i-1); } else
Reverse String Program in Java
Reverse String Program in Java We are going to describe about reverse string program in java. In this example reverses a string entered by the user. We... in String Java reverse string without using inbuilt functions
reverse words in a string(words seperated byone or more spaces)
reverse words in a string(words seperated byone or more spaces)  reverse words in a string(words separated by one or more spaces
String reverse program
String reverse program  write a java program for reverse string? if the string is "Hi welcome to hyderabad" the reverse string is "hyderabad... for help. You can split the String into String array using split method of String
Out of bounce exception in the string reverse program - Java Beginners
Out of bounce exception in the string reverse program  In the given... void main(String[] args) { String string=args[0]; String reverse = new StringBuffer(string). reverse().toString(); System.out.println
String reverse in java
String reverse in java In this section we are going to discuss about how to reverse a sting in java. There are many ways to reverse a string in java ... in java but in most interview they will ask to reverse a string without
String Reverse in Java
String Reverse in Java       In this example we are going to reverse a given string... the input string by using the StringBuffer(String string) method, reverse
Java program - convert words into numbers?
Java program - convert words into numbers?   convert words into numbers?   had no answer sir
Java Reverse String Pattern
Java Reverse String Pattern In this section, we have displayed a string in reverse pattern. For this,we have specified a string which is first converted... array and prnt it also. Here is the code Java Reverse String
reverse string
reverse string  how to reverse a string without changing its place...=input.nextLine(); String reverse = new StringBuffer(str).reverse().toString...{ public static void main(String[]args){ Scanner input=new Scanner
java program to convert decimal in words
java program to convert decimal in words  write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve
String Reverse In Java Example
String Reverse In Java Example In this tutorial we will read about reversing a String in Java. Here we will see how a String can be represented in its... a Java class where we will define a String constant, and then we will reverse
how to count words in string using java
how to count words in string using java  how to count words in string... java.util.*; class CountWords{ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
Reverse string in BlueJ
Reverse string in BlueJ  wap that user enter a string and one word. so i want that program search word in string entered by user if word exist in string than reverse only that word and give output. e.g This is a flower (string
string reverse order
string reverse order  Hi I have string s= " kalins naik" then how can i print string s=" naik kalins" Thanks kalins naik   import java.util.*; public class ReverseWords{ public static void main(String[] args
String Reverse Using StringUtils
String Reverse Using StringUtils       In this example we are going to reverse a given string using... and String.trim() for trim. The methods used: reverse(String str
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Reverse word of string in alphabetical order
Reverse word of string in alphabetical order  wap a program that reverse word of string in alphabetical order. e.g. input by user The purpose of education is to replace an empty mind with an open one output
Searching English words in a string
Searching English words in a string  My task is to find English words and separate them from a string with concatenated words..for example AhdgdjHOWAREgshshYOUshdhfh I need to find if there exists any English words.   
Count words in a string method?
Count words in a string method?  How do you Count words in a string... count the length of arr which return the number of words in the inputted string... java.util.StringTokenizer; public class StringCount { public static void main(String [] args
JavaScript split string into words.
JavaScript split string into words.  How to split string into words...; Description: The split() method is used to split a string into an array... which is used for splitting the string. If you don?t put any separator
print reverse string without api
print reverse string without api  accept a string and print reverse without using api
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
Getting the string in reverse
Getting the string in reverse  i am giving the string=" i am sachin".for this output is "sachin am i".please give me the code?   Hi Friend, Visit Here Thanks
Getting the string in reverse
Getting the string in reverse  i am giving the string=" i am sachin... static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String: "); String st=input.nextLine
Reverse integer array program
Reverse integer array program  Been tasked with the following... with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8.... I have this so far: public static int [] reverse (int a[]){ for ( int
Breaking the String into Words
into separate words. This program takes a string from user and breaks... between the words. This program also counts the number of words present in the string... Breaking the String into Words     
Java reverse string without using inbuilt functions
Java reverse string without using inbuilt functions In this tutorial, you will learn how to reverse string without using any inbuilt functions. Here, we have created a method to reverse the string and returns a new string with reverse
JavaScript reverse text string
JavaScript reverse text string...; In this section, we are going to reverse the text string using JavaScript..., you will get the reverse string in the same text box. Here is the code
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence... prints it is a magic string otherwise it prints not a magic string.  
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n... static void main(String args[]) { System.out.println("Enter the number"+n
Reverse String using Stack
Reverse String using Stack You all are aware of Stack, a data structure... in the reverse order from that in which they are added. The push operation is responsible for adding the element and pop for removing. Here we are going to reverse
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
java program for string tokenzing and parsing
java program for string tokenzing and parsing  String s="height=128 weight=22 gender=male"; i need to convert this into height="128" weight="22" gender="male" normally if we print "hello" means we use System.out.println("\"Hello
C String Reverse
C String Reverse       In this section, you will study how to reverse a string. You can see... shown above will reverse the string. Here is the code:  
Java count frequency of words in the string
Java count frequency of words in the string. In this tutorial, you will learn how to count the occurrence of each word in the given string. String... of words in a string. In the given example, we have accepted a sentence
Java: Example - Words to array
Java: Example - Words to array This example shows how to convert words to an array. We will use StringTokenizer to achieve the this.   Some times is is required to words into an array, to solve this you can use
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   The given code convert the string into words. import java.util.*; class StringExample
reverse arrays in java
reverse arrays in java  how do i write a program in array of size n*m where both n and m are greater than 20 such that the 1st element of an array becomes the last and vice verse
how to reverse a string without changing its place
how to reverse a string without changing its place  how to reverse a string without changing its place   Hi Friend, Another way of reversing string: import java.util.*; public class ReverseString{ public static
Reverse Order Java
Reverse Order Java   I am trying to get this into reverse order. Does... void main(String[] args) { Scanner kybd = new Scanner(System.in... static void main(String[] args) { Scanner kybd = new Scanner(System.in
String replaceFirst() Method
the following java program. In the program code given below, we have taken a String...;  In this program you will learn how to replace words in a text. We are going to use replaceFirst() method of String class in Java
Reverse - Java Beginners
Reverse   How to sort an array of strings(in reverse alphabetical... City{ public static void main(String[]args)throws IOException{ int count = 0; String arr[] = new String [4]; File f=new
Advertisements
 

 

 

DMCA.com