New to java help required :) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

New to java help required :)

What’s wrong with this code? Trying to make it go roar with an if else statement. class Dino { int weight; roar(){ System.out.println("Roar!"); } { public static void main(String[]args) { Dino t = new Dino(); t.weight = 5000; if (t.weight<=4000){ System.out.println("meow meow Your dino sounds more like a cat than a beast."); } else{ t.roar(); } } } }

2nd May 2018, 11:02 PM
Luis Rosado
Luis Rosado - avatar
3 Answers
+ 8
Your method roar is missing the return type declaration, type the keyword void (no return type), like this: void roar(){ ... } Also you need to remove the opening curly brace before the main method and one closing brace at the very end of your code.
2nd May 2018, 11:13 PM
Tashi N
Tashi N - avatar
+ 6
Just get rid of the curly brace just before public static void main. It shouldn't be there. And that will mean that you must also get rid of one of the braces at the bottom. Finally roar() needs a return type and since it returns nothing it must be: void roar(){ }
2nd May 2018, 11:11 PM
cyk
cyk - avatar
+ 2
Thank you guys, after you all pointed it out I noticed the extra curly. Totally forgot the void thank you all for your help.
3rd May 2018, 3:19 PM
Luis Rosado
Luis Rosado - avatar