• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problems with arrays

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
he every1,
can sum1please helpme here, i am really stuck.
i have a quston to do and iv no idea how to even start.
the question:
A standard pack of cards can be represented as an array of 52 integers with each number representing a standard card. Thus:

0 1 2 3 4 5 6 7 8 9 10 11 12 ..... 39 40 41 42 43 44 45 46 47 48 49 50 51

We can shuffle this pack of cards by randomly generating two indexes and swapping those two cards. For example if we randomly generate the indexes 8 and 50 and swap these two "cards" we would get (assuming this is the first swap):

0 1 2 3 4 5 6 7 50 9 10 11 12 ..... 39 40 41 42 43 44 45 46 47 48 49 8 51

After a suitable number of swaps have been made the pack can be said to be "shuffled".

Design and implement a Java programme which takes as input the number of desired swaps, outputs an ordered Set of cards which are then "shuffled" and output again. The number of swaps must be at least 1 and not more than 1000.
please please please help me with this.
any help at all is much appreciated
chris
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

It's a bit hard to understand your "IM-speak", but I'll do my best. If you can, when you reply, please spell words out to make it clear what you're saying. Thanks.

Now, on to your problem. The problem statement sounds very clear, actually. Assuming you know how to write, compile, and run "HelloWorld" in Java, the first problem is how to input the size of the array, yes? Is that where you're stuck?
 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your reply.
yes, i can understand and compile and execute the HelloWorld program, my problem here is that i cant actually understand what to do full stop. i know i have to shuffle the cards, its just this is my first study of arrays and i cant get my head around it. im just stuck.i dont know where to begin
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, well, as I said, the first thing would be prompting for and reading the size of the array from the user. Do you know how to do that?
 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no, sadly not, this is my first time with arrays so everything is new to me
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Note, though, that this first part has nothing to do with arrays.

Go have a look here and here, and see if you can put together a program that prompts for an int, reads it, and prints it back out. That'd be a start.
 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, i ve got that done
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Now allocate an array of that size, and use a loop to set the value of each cell in the array. Then use another loop to print out the value of each cell in the array. Now you've got a program that creates a "deck" of the appropriate size, and displays it.

By the way, it'd be OK for you to post each bit here as you get it.
 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic