Results 1 to 2 of 2
  1. #1
    npm1 is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Red face is this correct not supposed to edit the printValues method

    Java Code:
    /*
     * Fill in the class method main of the class ex3 with code that checks
     * to see if exactly one command-line argument is supplied:
     * -if more than one arguments are supplied, the program
     prints the string "Wrong input" directly from the main method
     * -if exactly one argument is suppled, the program prints the argument
     * args[0] by calling, from the class method main, the instance method
     printValues(s)
     * NOTICE that in the one argument case, you are not allowed to print
     the argument directly from the main method by using System.out.println
     * (or print).
     * nOTICE that in this case you need to call an instance method
     (i.e. printValue(s)) from a static class method(i.e. main).
     you are not allowed to create any new methods
     * all the code for this exercise must be inside the class method main
     *
     * for example.
     * if you run the program with "one" on the screen
     * if you run the program with "one two three" as command-line
     arguments, it should print "Wrong input on the screen"
     */
    public class Ex3{
        public void printValues(String s){
            System.out.println(s);
        }
        public static void main(String args[]){
            for(int i=0; i>args.length;i++)
            if(!args[i++].isEmpty()){
                System.out.println("Wrong input");
            } else{
            Ex3 a = new Ex3();
            a.printValues(args[0]);
            }
        }
    }
    is what i wrote correct

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    no, what you wrote is not correct:
    - braces don't match up
    - logic is incorrect

    did you try to run it?

Similar Threads

  1. JButton doesn't disappear when it is supposed to?
    By ecliptical in forum New To Java
    Replies: 4
    Last Post: 01-25-2010, 12:41 AM
  2. Is this the correct Output?
    By Teny in forum New To Java
    Replies: 17
    Last Post: 04-13-2009, 12:52 PM
  3. Help interpreting what a class is supposed to do
    By bornwithnoname in forum New To Java
    Replies: 2
    Last Post: 11-20-2008, 12:19 AM
  4. Is my Pseudocode correct?
    By Clemenza1983 in forum New To Java
    Replies: 0
    Last Post: 01-29-2008, 04:07 AM
  5. To correct forum
    By Jman in forum Introductions
    Replies: 3
    Last Post: 01-18-2008, 02:33 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
  •