+ 1
I don't understand the error
Sorry for the inconveniences, would you help me with this error that I do not know what happened. Why do I get this error if it's supposed to work. https://code.sololearn.com/cRJ7Wg8ayzWN/?ref=app
5 odpowiedzi
+ 4
Here you go... I have fix your code, it should work fine now with no errors
And you can not use methods inside a method...
If you have any questions or need any help... Please private message me😁 more than happy to help!
Fixed code...
https://code.sololearn.com/cCmB3k4lvcVw/?ref=app
+ 1
You can't write methods in method in java..
And you should write logic in methods but in second class everything you write in class level, and no method defined..
To execute a class method, you sholud have direct or indirect calling from main method.. But your 2nd has no way of executing it from main so it won't execute, even if it has proper methods..
+ 1
import java.util.Scanner;
public class Prueba1{
int a = 9, b = 5;
public void aviso(){
System.out.println(((a ^ b)* (a)/(15))/(b + a*b));
}
public static void main(String[] args) {
int repeat = 0;
Prueba1 base = new Prueba1();
Scanner num = new Scanner(System.in);
System.out.println("please tell me how many times will it repeat");
repeat = num.nextInt();
for(int i = 0; i < repeat; i++){
base.aviso();
}
}
}
THIS IS THE CORRECT CODE.
There were a number of mistakes. They are :
1. Do not write methods under main() .
2. The output is 0 as you have declared "integer" data type.
3. You have to write the syntax of the input statement correctly :
Scanner num = new Scanner(System.in);
repeat = num.nextInt();
// variable = <variable of scanner line>.next<data type>.
SOME IMPORTANT NOTES :-
YOU HAVE TO PRACTICE A LOT OF PROGRAMMING AND
YOU HAVE TO STUDY THOROUGHLY THE BOOK AND UNDERSTAND THE CONCEPT AND LOGIC OF PROGRAMMING.
INSUFFICIENT KNOWLEDGE IS NOT AT ALL ACCEPTABLE.
YEAH YOU TRY THE CODE BUT DO NOT MAKE IT "PUBLIC" UNLESS YOU ARE SATISFIED WITH THE OUTPUT. ONLY UNDERSTAND AND CLEAR YOUR CONCEPT AND PRACTICE A LOT OF PROGRAMS . YOU CAN ALSO COMPLETE THE JAVACOUSRE WHICH IS AVAILABLE HERE ON THIS PLATFORM .
OK , I THINK YOU WILL FOLLOW THESE WORDS AND YOU WILL SURELY BECOME A GREAT DEVELOPER 1 DAY .
0
First error to fix is, that you declared a method (void aviso) within the main method. Methods may not be nested.
0
import java.util.Scanner;
// public
class Prueba1{
double a = 9.0, b = 5.0;
void aviso() {
System.out.println( (Math.pow(a,b) *a /15.0) / (b + a*b));
}
}
public class respuesta {
public static void main(String[] args) {
int repeat = 0;
Prueba1 base = new Prueba1();
Scanner num = new Scanner(System.in);
System.out.println("please tell me how many times will it repeat");
repeat = num.nextInt();
for(int i = 0; i < repeat; i++){
base.aviso();
}
}
}