Java programming Input:Today is Sunday Output:Sunday is today [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
String str="Today is Sunday"
And the output should be "Sunday is Today"
I need a code for this program in Java.
Is there any other method to do it...

This feels like a question for a university assignment, but in essence, you need to split the array then reverse it.
var elems = inStr.split(' ');
elems.reverse();
Unless I'm misunderstanding the question.
For the record, JavaScript and Java are different languages, and I've written JavaScript.
EDIT: In Java, it's something like this:
String inStr = "today is thursday";
String[] elems = inStr.split("\ ");
You can then just loop backwards over the array.

In javascript, you can use push() method to store value into array, It adds the new item into end of the array.
var arr = [];
arr.push('Today')
arr.push('is')
arr.push('sunday')

Related

Find all the occurences of an array that contain a substring in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Input:
[the, and, land, wander, dreams]
Substring: "and"
Output: 3
I need to find all the occurrences of an array that contain a certain substring but all I found was the word itself. For example, I want it to count the "and" in the word "land" and "wander" as well. I don't know how to do that. Please help!
EDIT: Updated the code.
What about:
int cnt=0;
String[] input = {"the", "and", "land", "wander", "dreams"};
for (String str : input){
if (str.contains("and")){
cnt++;
}
}
System.out.println(cnt);
This code should work for you. But keep in mind following - Exbow is right, next time your question might be considered as useless and will be closed.

Use the value that a function returns as the name of a new Array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Good I am trying to create a function that generates new Array, and trying to use a getter method that returns a name for example ArrayD5, ArrayD10 and use these as the name of the new arrays to generate.
I have tried to do this:
int length = 5;
String (SeatIbiza.nombres(length))[] = new String[length];
String nombres (int length) {
return "ArrayD"+length;
}
If you are looking for a way to declare something like e.g.
String "ArrayD" + 2
so that you have a variable
String ArrayD2
then this is not possible in Java. Dynamic naming of variables is not supported.
I don't think if that's possible. The variable names are required to be declared during compile time in JAVA and dynamic naming isn't supported... yet.
Correct me if I'm wrong as I'm still learning about JAVA

Java mismatch between String and String[] [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm using Java to implement the Apriori algorithm but one problem exists.
ArrayList<String> l1=new ArrayList<>();//L1
...
ArrayList<String[]> lk1=l1;//Lk-1
Then it warns that: cannot convert from ArrayList<String> to ArrayList<String[]>. How can I solve this problem?
They're different types. Ignore the collection and just look at the underlying type.
String str = "This is a string.";
String[] array = str;
These are two different types, unconvertable, so as T for the collection, the collections are then unconvertable. Very basic concept here.

java string add comma become array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
String items = "bookcupdoll";
I want to add a comma in items variable like below:
book,cup,doll
How should I make the string become an array?
If you are asking how to convert a string to an array...
There is a handy method called "split(String separator)"
If the string looks like : String items = "book,cup,doll";
you can use it like this
String[] array = items.split(",");
And you will end up with an array of size 3 with the 3 different elements.

Writing a method using getArray() in Java that returns an array of integers [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am in a a JAVA programming class online and I need some help with making an array. I have asked some fellow class mates to no avail. I need to make write a method using the getArray() method that will return an array of integers with the capacity of 500.
I do know how to write a JAVA statement that initializes an array of integers with a capacity of 500. However, it nots helping me much. (i named the array "values")
int [] values = new int [500];
Please be timely if you answer this. I need to know how to do this before Wednesday 2/5/14 Thank You
public int[] getArray(){
return new int[500];
}

Categories

Resources