Not able to compile the program shows ".class expected" [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 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);
^ ^

Related

Java Syntax error on token ";" - What am I doing wrong with this for loop? [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 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);
}
}
}

why this java code run smoothly by sublime and cmd ,not work in eclipse? [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 days ago.
Improve this question
public class Object03 {
public static void main(String[] args) {
Person p2 = new Person();
p2.speak();
}
}
class Person{
String name;
int age;
public void speak() {
System.out.println("I am a good person");
}
}
It says "The type person is defined" in row 13 in eclipse.But it works fine if i write it in sublime and use cmd to compile and run it.enter image description here

How to make a summ Method in Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
recently my teacher showed us how to make a summ methode but i cant remember it.I think i got it a bit ritght.But it tells me error unexpected token a
void main(){
summ(6, 7);
}
int summ(a, b){
a = int
b = int
return a+b }
It should be like this
static int summ(int a, int b)
{
return a+b;
}

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.

Categories