Results 1 to 4 of 4
  1. #1
    ElmuKelmuZ is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Variables, If, else

    I have experience of Lua, and Ive lately started to learn Java.
    I made this simple program to test if- and else-statements in Java, however something here is wrong, and I do not understand the error that output gives me.

    import java.io.*;
    class Main {
    * public static void main (String[] args) throws Exception {
    int num = 15;
    string str = "Hey";
    string str2 = "hey";

    if (num == 15)
    * * System.out.println("If!");
    else
    * * System.out.println("Else!");

    if (str ~= str2)
    * * System.out.println("Strings not equal");
    else
    * * System.out.println("strings equal!");

    * * BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    * }
    }

  2. #2
    killutch is offline Member
    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    0

    Default Re: Variables, If, else

    whats with all the asterisks? its not going to compile with all the **. I would suggest taking them all out except the one in import.java.io.*

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Variables, If, else

    Yes, get rid of the asterisks and instead use [code] [/code] tags around your code blocks posted on the forum.

  4. #4
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    177
    Rep Power
    2

    Default Re: Variables, If, else

    Alright I copy and pasted it into my computer to find your errors. and here is what i found(

    1. Don,t use asterisks except for the import.

    2.when declaring a non primitive like String you must captilize it in the declaration on line 5&6.

    3.I assume since you said you used lua that you put ~for dont on line 13. It does not mean that in Java replace it with a !.

    4.I dont know if you have some special use or not for it but i ran the program fine in my command prompt without the import,BufferReader,and InputStreamReader.
    Last edited by Daryn; 10-10-2012 at 01:54 AM. Reason: adding number 4

Similar Threads

  1. 2 variables get linked
    By JavaNoob84 in forum New To Java
    Replies: 4
    Last Post: 11-30-2011, 09:41 AM
  2. help with variables please
    By arimaliz in forum New To Java
    Replies: 3
    Last Post: 03-22-2011, 04:30 PM
  3. Listening for variables?
    By martypapa in forum New To Java
    Replies: 6
    Last Post: 02-09-2010, 09:14 AM
  4. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 05:48 PM
  5. Variables
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •