Results 1 to 4 of 4
  1. #1
    FearTheMan is offline Member
    Join Date
    Mar 2015
    Posts
    2
    Rep Power
    0

    Default What is wrong with my code?

    I have this JAVA written but I can't get the parameters for the if statements right.
    import java.util.Scanner;

    public class myFirstJAVA {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    System.out.println("Please enter command: ");
    String text = input.nextLine();

    if(){
    System.out.println("Machine Started");
    break;
    }
    else if(){
    System.out.println("Machine Stopped");
    break;
    }
    else{
    System.out.println("Command Not Recognized");
    }

    }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: What is wrong with my code?

    Please place your code between [code][/code] tags to preserve formatting. And your conditional expressions are not present. Nor have you explained what the conditions should be. So how could anyone possibly help you? And fyi, Java is not an acronym.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    FearTheMan is offline Member
    Join Date
    Mar 2015
    Posts
    2
    Rep Power
    0

    Default Re: What is wrong with my code?

    Sorry I just started programming yesterday and I'm not really sure where to start learning

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: What is wrong with my code?

    Quote Originally Posted by FearTheMan View Post
    Sorry I just started programming yesterday and I'm not really sure where to start learning
    Well, I recommend two things. Get a book on Java Programming and also take a look at the tutorials linked in my signature. Unfortunately, I do not have a good recommendation for a general purpose Java book. You may want to ask some of your peers or an instructor what they recommend.

    Regarding your posted code above, you need to decide under what conditions you want the text to be printed. Example:

    Java Code:
    int a = 2;
    if (a == 2) {
       // do something
    } else if (a == 3) {
       // do something else
    } else {
       // do this for every other value of a
    }
    Regards,
    Jim
    Last edited by jim829; 03-01-2015 at 10:51 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Help please, what's wrong with my code?
    By jamgor in forum New To Java
    Replies: 9
    Last Post: 06-12-2013, 03:35 AM
  2. What is wrong in my code
    By janmjeay in forum New To Java
    Replies: 3
    Last Post: 06-08-2013, 04:56 AM
  3. What is wrong with that code ?!
    By qwerty53 in forum New To Java
    Replies: 5
    Last Post: 07-12-2011, 01:34 PM
  4. pls tell wat wrong with my code???
    By low224 in forum New To Java
    Replies: 13
    Last Post: 01-11-2009, 07:40 AM
  5. what is wrong with this code
    By masaka in forum New To Java
    Replies: 5
    Last Post: 04-16-2008, 08:27 AM

Posting Permissions

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