Time complexity difference in System.out.println() [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 5 years ago.
Improve this question
Why is System.out.println("Hello World"); O(1) and System.out.println(str); O(N)? Can somebody explain the difference?

"Hello World" is a constant so it is O(1) whereas string str is variable of length n so the complexity is O(n)

Related

Next Greater Element zoho [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 days ago.
Improve this question
Given a circular, integer array nums, return the next greater number for every element in nums.
Input
[9,1,2,4,3,5,8]
Output
[-1,2,3,5,4,8,9]
In other words:
9->-1
1->2
2->3
4->5
3->4
5->8
8->9
I'm very confused how to solve this problem. Please help me.

Return method return several times [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 5 years ago.
Improve this question
I want to make a method return that return several times a String from a list of String. any idea ??
How about something like this:
String getRandomString(List<String> list) {
return list.get(new Random().nextInt(list.size()));
}
This isn't the most efficient way, but should do the job.

How do I use only one element of an ArrayList? 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 7 years ago.
Improve this question
If I have an initialized array in Java and I want to do a method to one element in that array I would do
array[n].method();
but how do I do the same thing with an arraylist?
arraylist[n].method() gives me an error.
With Java use get method with ArrayList:
arraylist.get(n).method();

How to parse String vars 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 8 years ago.
Improve this question
What is the best way to parse a String value that looks like this id#1 ...id#398, so I can get de number after the id# String in JAVA.
If id# is a fixed prefix in every ID, I would have used
stringValue.split("id#")[0]

how to calculate the time complexity for the following code? [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 9 years ago.
Improve this question
For (int i=1; i <=n;i/=2){
System.out.println(i);
}
For the time complexity about the above coding, is ot log (n)?
Thanks!
If n > 0: It's time complexity is O(∞) because the loop will never end
If n <= 0: It's time complexity is O(1)
because the loop will not be executed

Categories