Page 7 of 7 FirstFirst ... 567
Results 121 to 136 of 136
  1. #121
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    how does this look?

    Java Code:
    int[] test = new int[5];
    			test[0] = 7;
    			test[1] = 6;
    			test[2] = 5;
    			test[3] = 4;
    			test[4] = 2;
    			String x = "";
    			for(int i = 0; i < test.length;i++)
    			{
    				x += test[i];
    			}
    			System.out.println(x);
    ...and yeah I don't know where I was getting at with the toString

  2. #122
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,424
    Rep Power
    25

    Default Re: Help with arrays

    What is the code supposed to do?
    Does it do it?

  3. #123
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    It does what I want it to, but I just wanted to see if that looks like 'good' code to you.

  4. #124
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,424
    Rep Power
    25

    Default Re: Help with arrays

    You can initialize an array in one statement:
    int[] test = new int[] {1,2,3,4,5};

  5. #125
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    wow, i'm dumb. thank you. I feel like a new that, but I hate working with array's so I tend to forget how to do everything

  6. #126
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    Okay, now I have a problem that needs some explaining.
    This is the code:
    Java Code:
    public static void main(String[] args)
    		{
    			Scanner inputTest = new Scanner(System.in);
    			String tester = sumPrint(randomNumber());
    			String input = inputTest.next();
    			if(input == tester)
    			{
    				System.out.println("You are correct!");
    			}
    			else{
    				System.out.println("Sorry, incorrect");
    			}
    		}
    I debugged this, and if I do input the right value I see in the debugger that input = tester, however I still get the output "Sorry, incorrect"

    So the values show the same in the debugger, yet they aren't the same since it says I'm wrong

  7. #127
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,424
    Rep Power
    25

    Default Re: Help with arrays

    Use the equals() method for comparing Strings.

  8. #128
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    right... forgot about that one... thank you

  9. #129
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    How would I go about creating something that would let me run this program without using a compiler?

  10. #130
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,424
    Rep Power
    25

    Default Re: Help with arrays

    By definition a compiler is what reads your source file, makes sense of it and creates a class file or some intermediate form.
    I don't know of any alternative.
    Even an interpreter has a compiler component.

  11. #131
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    So I guess what I am asking is if it is possible for me to compile this code into a file that I can, for example, e-mail it to someone, and then have them just download it and then run the program without having eclipse or some other program

  12. #132
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,424
    Rep Power
    25

    Default Re: Help with arrays

    Java class files require a JRE to execute them.
    Normally you put the class files into a jar file with a manifest file. The jar file can be executed on a PC with the JRE installed.

  13. #133
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    how on earth would I go about doing that?

  14. #134
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,424
    Rep Power
    25

    Default Re: Help with arrays

    The jar command will create jar files.
    Any one that wants to use the jar file would have to download and install the JRE

  15. #135
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Help with arrays

    can you point me towards an article or tutorial for that?

  16. #136
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,424
    Rep Power
    25

Page 7 of 7 FirstFirst ... 567

Similar Threads

  1. Casting Enum Type arrays to object type arrays
    By nmvictor in forum Advanced Java
    Replies: 4
    Last Post: 02-17-2012, 12:49 PM
  2. arrays and multidimensional arrays
    By belfast09 in forum New To Java
    Replies: 5
    Last Post: 06-14-2011, 01:28 PM
  3. help with arrays
    By droidus in forum New To Java
    Replies: 20
    Last Post: 04-19-2011, 06:29 AM
  4. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 10:32 AM
  5. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 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
  •