error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

error

please what does these mean and how do i correct them "..\Playground\\.java:15: error: reached end of file while parsing } ^ 1 error" almost all the codings I try to do gives me that . it very discouraging some one here should help me out

18th Dec 2018, 10:48 PM
Eli Governor
Eli Governor - avatar
11 Answers
+ 2
You are welcome ☺️ When you declare a variable once you dont need to declare it again, you can use it, change it everytime you need without declaring it (that is adding the type like int double etc) for using it just call it by the name! Example: int age = 0; //declare the variable age age = 10 // change the value of age to 10 double height = 13.5 // declare variable height height = 5.5 // now height is changed
19th Dec 2018, 12:52 AM
Sekiro
Sekiro - avatar
+ 2
You were declaring the same variable in age 2 times, second time no need to write int! Also, you were missing one curly brace to close the if statement!
19th Dec 2018, 12:29 AM
Sekiro
Sekiro - avatar
+ 1
public class Program { public static void main(String[] args) { int age = 25; int money = 100; if (age > 18 || money > 500) { System.out.println("Welcome!"); double hieght = 13.7; age = 45; // here you declare the same variable 2 times, no need the "int" if ( hieght <= 14 || age > 50 ) { System.out.println("Congratulations"); } } // here you missed one curly braces } }
19th Dec 2018, 12:28 AM
Sekiro
Sekiro - avatar
+ 1
Thanks Sekiro
19th Dec 2018, 12:31 AM
Eli Governor
Eli Governor - avatar
+ 1
Does that mean I don't need to declare age anymore or I just don't need the "int" again
19th Dec 2018, 12:32 AM
Eli Governor
Eli Governor - avatar
0
Please post one of your code so we can see where is the problem!
18th Dec 2018, 11:33 PM
Sekiro
Sekiro - avatar
0
public class Program { public static void main(String[] args) { int age = 25; int money = 100; if (age > 18 || money > 500) { System.out.println("Welcome!"); double hieght = 13.7; int age = 45; if ( hieght <= 14 || age > 50 ) { System.out.println("Congratulations"); } } }
19th Dec 2018, 12:20 AM
Eli Governor
Eli Governor - avatar
0
That's an example of the codes
19th Dec 2018, 12:20 AM
Eli Governor
Eli Governor - avatar
0
Perfect!!! I get it now I think my problem are with the curly braces can you teach me an easier way to get it . For instance I just wrote this code and I error was printed public class Program { public static void main(String[] args) { int day = 3; switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; int month = 3; switch ( month ) { case 1: System.out.println("January"); break; case 2: System.out.println("Febuary"); break; case 3: System.out.println("March"); } } } }
19th Dec 2018, 1:03 AM
Eli Governor
Eli Governor - avatar
0
Yes firenzy james , you need to understand more about the curly braces, in that code you need to close the switch statement before you open another one (unless you want to do nested statement but that is different topic). for example: swich(day) { //do stuff here } switch(month) { //do other stuff here } It would be a good design choice to always close the curly braces when you finish to use a statement or a function! statement or function or class { //do what you need to do then close it } An example of good program should be like this: class { function { // declare variables if statement { // do stuff } switch statement { // do stuff } } // this is for closing function } // this is for closing class I would suggest you to go through the tutorial on Java here on SoloLearn if you havent already!
19th Dec 2018, 4:37 AM
Sekiro
Sekiro - avatar
0
I would write the above code like this: public class Program { public static void main(String[] args) { int day = 3; int month = 3; switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; } switch ( month ) { case 1: System.out.println("January"); break; case 2: System.out.println("Febuary"); break; case 3: System.out.println("March"); } } }
19th Dec 2018, 4:43 AM
Sekiro
Sekiro - avatar