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
Related
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 days ago.
Improve this question
So my program is working , the program is to check if a number is Automorphic,Trimorphic,Tri-Automorphic or its not a type of automorphic.
But I have a doubt , that is , what does this do:
for (I = a ; I> 0 ; I = I / 10 )
{
C++;
}
I tried to remove C++ but that didn't work.
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.
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
I have part of the code:
public void CollectorOrPocrushka(double output) {
if (output <= 0.4999999999999999999999)
System.out.println("покришка");
if (output > 0.5 && output <= 1.0)
System.out.println("колектор");
}
Can I write float number 0.4999999999999999999999 shorter?
Something like that:
0.49F
0.49e^10
If your question is about to simplify the first if condition and your goal is to check if the output is less than or equal 0.4999999999999999999999, you can easily write
if(output < 0.5)
System.out.println("покришка");
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)
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
Hi in the below code mandatoryCount = 0 and it should be increased when an image is selected but its found to be always 1 and i cant exit the loop can any one help me. Here if mandatoryCount = 0 or mandatoryCount>=imageTypeMandatory.length. It must come out of loop. But this code is working if i comment the mandatory count ==0. I cannot find the exact error.
if (dataOne.getCount() >= 1) {
mandatoryCount=0;
dataOne.moveToFirst();
while(!dataOne.isAfterLast()){
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){ if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++; imageTypeMandatoryCopy[iCopy]="";
}}
dataOne.moveToNext();
}
The logic is testing the moveFirst/moveNext.
if (dataOne.moveToFirst()) {
do {
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){
if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++;
imageTypeMandatoryCopy[iCopy]="";
}
}
} while(dataOne.moveToNext());
}