Im getting confused on the if/else statement for Java


#1



https://www.codecademy.com/en/courses/learn-java/lessons/conditionals-control-flow/exercises/if-else

These are my error messages:
IfElse.java:3: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:7: error: class, interface, or enum expected
} else {
^
IfElse.java:11: error: class, interface, or enum expected
}
^
3 errors


Replace this line with your code.


#2

As it says, only those three statements are allowed at the top level of the file. Put your code in a method, which in turn has to be in a class.


#3

still confused w w w w w w w w w


#4

that just gives me this:
IfElse.java:1: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:1: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:1: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:1: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:1: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:1: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:1: error: class, interface, or enum expected
if (7 < 7) {
^
IfElse.java:3: error: class, interface, or enum expected
System.out.println("Try again...");
^
IfElse.java:5: error: class, interface, or enum expected
} else {
^
IfElse.java:9: error: class, interface, or enum expected


#5

In the beginning of the lesson I deleted that part at the top(I wanted to see what it would do). Then I followed through the lesson like I normally would but it ket giving me errors. That's when i came here. I previously did JavaScript and I mastered if/else statements and it won't work here. Just asking, what does this part of the code even do:
public class If {
public static void main(String[] args) { ?


#6

This is just to clarify.I have no idea what a class or a method is . I just started java and have no idea what those things are. In the beginning I deleted the class part at the top to see if that did anything , and it did. So could someone please just copy and paste the top part of the code for lesson 7 of Conditionals and Control Flow for Java. The only reason why i want someone to copy and paste is because i don't know what the code I'm missing does or is. I understand what the lesson wants me to learn so copying and pasting the code at the top won't help me learn anything or cheat. Please help


#7

Can you check what I wrote back to you


#8

If you want to know what some concept is then google is your friend, start there. Here are two suggestions, but there are many others
https://docs.oracle.com/javase/tutorial/java/concepts/class.html
https://howtoprogramwithjava.com/what-is-a-method-in-java/

The classname should be IfElse, same as the filename, and it needs a method named main which is what's used as the entry-point for your program


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.