Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have array list that each indexes has value either 0 or 1.I want to find that continuously three indexes has the value 1.How do I find it?
Without actual code:
iterate thorough the array
count the 1s you found
if you found a 0 then start over the count
check after increasing the counter: if the counter reaches 3 then return with true
if you reached the end of the array and no more elements then return with false
Something like this, I hope I could help.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
This question was asked before and looked that without sorting and multithreading one simply needs to iterate through all elements. Is there any other idea? Java implementation is fine
If there are no other prerequisites for the input array, then no: You have to iterate through all the elements until you find the one you are looking for (thus, in worst and average case that would be O(n)).
If you have something else (like a heap, a search tree or any otherwise sorted array) you can use smarter and much faster techniques, of course (e.g. binary search).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have some specific task. We have String like "(()[]<>)" or something familiar with this.
A question in my interview qustion was how check either String is correct or incorrect.
For example: "()[]<>" - true, "([)" - false, "[(])" - false, "([<>])" - true.
Thank you guys very much!
You would need to use a stack to process this.
When you find a new opening parenthesis you would push onto the stack.
When you find a closing parenthesis, peek at the top element on the stack - and see if it matches. I.e. if you've just found a ")", was the last element on the stack a "("?
If it was, then pop that element of the stack. If it wasn't then you've got an "incorrect" String and you can stop processing any further.
Also, once you get to the end of the string, if there's anything left on the stack we know there's an non-terminated parenthesis.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What I am looking to do is split a given string in Java using a tab delimiter. After the seventh split, I would like to keep everything after that point as an eighth split. This last split will contain tabs also, but must remain intact.
Use the split method that takes two parameters, the second being the split limit. You can pass in a limit of 8. The eighth element will contain the rest of the string after the seventh split.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have to create a random cellnumber 07939393914 for automation testing purpose.
Last 079393(5 digits) digits should change randamly.. each time test runs..
Can any one suggest JAVA code for this ? or else Selenium Java code ?
Thanks
Is this a number or a String? I ask as it has a leading zero.
Take you initial number as 7939300000
then add to it Math.round(Math.Random()*10000)
If you want it as a String, take your string as "079393" and use Integer.toString on the result above, then concatentate them
Use RandomStringUtils class.
String randomNumbers = RandomStringUtils.randomNumeric(5);
String phNo = 079393+randomNumbers;
var num=Math.ceil(Math.Random()*100000)
for random first 5 digit numbers
and add
var your_last_5digits; //as string to your last 5 digits
cellNumber='0'+num+your_last_5digits;