tags:

views:

70

answers:

4

Question 1. I want to print my from the

String s = " This is my house";

using core java?

Question 2. I want to print house is my This from the

String s = " This is my house ";

using core java?

A: 

You need to look into using System.out.println() for outputting stuff to the console.

If you want to split your string into words and print them in a different order, you need to look into using String.split() to create an array of words separated by white space, then a loop to output them in a different order.

The String.split() stuff can be found here.

Once split() has extracted your words into an array with four elements, the rest of the question is achieved by printing the third element (for your first question) or elements 4, 2, 3 and 1 in that order (for your second question).

That's assuming your question is correct and you didn't want the words in reverse order. And keep in mind that the first element of an array has an index of 0, not 1.

paxdiablo
+6  A: 

Hint - look at the methods the String class offers. There's substring, indexOf, split and some other useful things for that task.

Andreas_D
+1 That's enough to solve it.
Thomas Jung
A: 

System.out.println(s) will print the string s. For your second question, you should consider using String.split() to split your String on spaces, and then sort the resulting array.

uckelman
A: 

If this is a "tokenization" question you should check out StringTokenizer that is useful to split a string into words, then you should know how to process them with or without an array and

  1. take third element for first question
  2. reverse array or choose explicitly elements for second question
Jack