How to write double number shorter in java? [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 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("покришка");

Related

What does for(i = a; i> 0;i=i/10) do? [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 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.

Java / "Advanced" Checking [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 5 years ago.
Improve this question
I am trying to make a program where I can't find a solution for this:
I want to check if position_x is 0 or 20 or 40 or 60 or 80 or 100 or 120... until 1280 (always plus 20).
I hope you can help me further,
Thanks!
You can try using the modulus here, e.g.
if (position_x % 20 == 0 && position_x >=0 && position_x <= 1280) {
System.out.println("position_x is a multiple of 20 and within range.");
}
else {
System.out.println("position_x is out of range or not a multiple of 20.");
}

How to print a number with commas as thousands separators in Java..And I also want to print just 2 number after the point [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 trying to print this integer 12345679 like 1,234,68. I was trying to do like this.
System.out.println(count+" "+"$"+fm.format(NumberFormat.getNumberInstance(Locale.US).format(avg)));
How can I do this in java??
NumberFormat currencyInstance = NumberFormat.getCurrencyInstance(Locale.US);
currencyInstance.setMaximumFractionDigits(0);
System.out.println(currencyInstance.format(12345679));
Output: $12,345,679

How do I convert this to a compareTo line(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 9 years ago.
Improve this question
while (in > h-1 && n[in-h] >= wrapperTemp)
I am writing a program but it deals with objects, so using the >,>=, symbols aren't going to help me in this case.
in, h, and wrapperTemp are all variables.
- this is written in the java language
I think you just want this
while (in.compareTo(h-1) > 0 && n[in-h].compareTo(wrapperTemp) >= 0)
Try,
while (in > h-1 && (n[in-h].compareTo(wrapperTemp) >=0))

Its not coming out of the loop [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
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());
}

Categories