If-Condition for double [closed] - java

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have this code:
public static void main(String args[]) {
double server = 2.11;
double client = 2.8;
if (server > client) {
System.out.println("Upgrade");
} else {
System.out.println("Not Upgrade");
}
}
But it returns:
Not Upgrade
I don't know what's happening with If Conditions and double data type. Anyone?

Last time I checked, 2.11 was less than 2.8.
Consider representing version 2.8 as 2.08, or perhaps (better) using an integer, e.g.:
int version = (major << 8) | minor;

Oops sorry, I got it now
just like in the comments 2.8 is 2.80 > 2.11

Related

getting syntax error for else in java [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I started learning core java from youtube but while writing same code in eclipse i am getting syntax error .
package Javatut;
public class ifelse {
public static void main(String[] args) {
int test = 10;
if (test == 10);{
System.out.println("yes");
}
else{
System.out.println("No");
}
}
}
I suggest you use an IDE as this will help you find such issues. After using the auto-formatter, I can see this warning in IntelliJ
You can see that the formatting is not what you think it should be as you have an extra ; in your code.

missing return statement even method is having void return type [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
am writing a java program as below.
Void fun(int n){
for(int i=0;i<=n;i++){
fun(n-i);
}
System.out.println(“well done”);
}
I am getting error, missing return statement. I not used int or string method. It is void method na. why it asking return type, please help for this problem.
Void is a reference type.
void is a language primitive.
You don't need a return statement when your return type is void.

Why assertions in Java is not working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I tried to use assertions in java from an example put forth from a site but it is not throwing an Assertion Error even if it does not conform to the requirements.
Where am I doing wrong?
package Sources;
import java.util.Scanner;
public class MyAssertion
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your age");
int age = scanner.nextInt();
assert age>=18:"Not Valid !!";
System.out.println("Age is -- "+age);
}
}
I have also used the following command :
java -ea -cp ./classes Sources.MyAssertion
But even if I enter the age as 33 it is not throwing an error . Why?
Any help is much appreciated :)
Assertions fire when the condition is not true. If you enter 33 then that is greater than equal to 18, so all is well.

Scientific Notation as a Double java Android [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
If this was a string and it was parsed as a double. Would java be able to process this as the expected value or would I need to change the format of these numbers? Would I need to remove the "+" or change e to "E"?
1.3870574e+01
The string parsed to a double just fine on my system.
See Double.valueOf(String str)

Mod not working the way I expect [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I'm trying to count the number of items in a scanner object which are divisible by 2.
My code looks like this:
while (s.hasNext()) {
num = s.nextInt();
if ((num % 2) == 0); {
count++;
}
}
For every integer in the object though, count is increasing by 1, regardless if it is divisible by 2, or not. Can someone tell me what I'm doing wrong?
You have a semicolon (;) after your if clause. That means empty code is executed if the condition is true and the code in the code block is always executed.
The ; after the if should be omitted

Categories