answersLogoWhite

0


Best Answer

/* Input: Do Your Duty

* Output: Duty Your Do

*/

import java.io.*;

class RevSent

{

protected static void main()throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the Sentence: ");

String s=in.readLine();

char ch; short a=0,b=0;

for(short i=0;i<s.length();i++)

{

ch=s.charAt(i);

if(ch==' ')

a++;

}

String w[]=new String[a+1];

for(short i=0;i<=a;i++)

w[i]="";

for(short i=0;i<s.length();i++)

{

ch=s.charAt(i);

if(ch==' ')

b++;

else

w[b]+=ch;

}

for(short i=a;i>=0;i--)

System.out.print(w[i]+" ");

}}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

import java.io.*;

class RevWords

{

private byte wo(String s)

{

byte a=0;

for(byte i=0;i<s.length();i++)

{

if(s.charAt(i)==' ')

a++;

}

a++;

return a;

}

protected static void main()throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

RevWords o=new RevWords();

System.out.print("Enter the String: ");

String s=in.readLine();

byte a=o.wo(s),b=0;

String w[]=new String[a];

for(byte i=0;i<a;i++)

w[i]="";

for(byte i=0;i<s.length();i++)

{

if(s.charAt(i)==' ')

b++;

else

w[b]+=s.charAt(i);

}

b=0;

for(byte i=0;i<a;i++)

{

for(byte j=(byte)(w[i].length()-1);j>=0;j--)

System.out.print(w[i].charAt(j));

System.out.print(' ');

}

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in java to print a statement in reverse order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you write a thesis statement in any order?

No.


How can you generate a palindrome from a given number?

You write the number and then follow it with the digits in reverse order.


How do you program a reverse auto loan calculator in JAVA?

In order to program a reverse auto loan calculator in JAVA, you are going to need a lot of experience with JAVA. There are online tutorials that can help you set up with fundamentals of JAVA so that you will be able to create almost any basic program you want.


What is a silly way to remember the planets backwards?

Write the names in order on a piece of paper, then turn it upside down and you can read the names in reverse order.


What is a member of the Benedictine order called?

This is a statement you need to write a question


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student?

write a program which reads names of students and their telephones from a file and produce a linked list ordered in alphabetical order by the surname of the student.


How would you write turquoise foundation brought mouthful and sprawls in reverse alphabetical order?

turquoise, sprawls, mouthful, foundation, and brought


Write a c program for alphabetical order?

int main (void) { puts ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); return 0; }


What is the order of processing?

first you find theise statement and summerize it then you write a paragraph on the process its alot to do so yeah i think this is right


Statement of polygon law of forces?

if several COPLANAR FORCES are acting at a point simultaneously such that each one of them can be represented in direction and magnitude by a side of a polygon, taken in order, then the resultant is given by the closing side in the reverse order


When you multiply or divide an inquality by a negative number you must reverse the sense of inequality why?

You must reverse the sense of inequality because, in essence, you're taking the opposite of both sides. In order to more properly show this, here's an example. 3&gt;2 Three is greater than two. True statement, right? Let's multiply both sides by -1 -3&gt;-2 The statement is no longer true. In order to keep the equation true, you must flip the inequality. As in -3&lt;-2 Now, the statement is true again.