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.
Related
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 days ago.
Improve this question
I have the below code and am trying to figure out why it is throwing an error. I am getting Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token ";", delete this token
at LearnJava.main(LearnJava.java:7)
public class LearnJava {
public static void main(String[] args) {
for (int i = 10; i >= 0; i++;){
System.out.println(i);
}
}
}
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
import static java.lang.Math.pow;
public class Power2
{
public static void sampleMethod(int y)
{
long r=0;
for(int i=0;i<=y;i++)
{
r =long(Math.pow(2,i));
System.out.println("2*"+i+"="+r);
}
}
}
Casts require parenthesis
r = (long) Math.pow(2,i);
^ ^
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.
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.
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