The Artima Developer Community
Sponsored Link

Java Answers Forum
dice roller

1 reply on 1 page. Most recent reply: Mar 11, 2006 9:20 PM by joe auerbach

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
joe auerbach

Posts: 14
Nickname: anivair
Registered: Feb, 2006

dice roller Posted: Mar 11, 2006 6:53 PM
Reply to this message Reply
Advertisement
I'm working on a dice roller (for fun and knowledge). I have a question about the following code. This snippet is meant to be a basic menu that will prompt the user for a number of dice as the number of sides on each one (which will be fed into an array (number of dice) and a random number generator (sides).

    public int menu()
    {
        int sds = 0;
        int dic = 0;
        do
        {
        System.out.print("How many sides does your die have? ");
        
        sds = sc.nextInt();
        
        System.out.println("");
        System.out.print("How many dice am I rolling, here? ");
        
        dic = sc.nextInt();
        }
        while (sds > 0 && dic > 0);
        
        return sds;
        return dic;
    }


When I try to compile it I get "unreachable statment" at 'return dic;'. if I remove 'return dic;' the program compiles ust fine, but I'm iffy on the return statment and it's function. Will I be able to call these variables later without it? And if so, why do I have the previous statment?

Is the situation that I should have 2 sections here? One for the sides and one for the number of dice, each returning one variable?

Thanks in advance for any help.


joe auerbach

Posts: 14
Nickname: anivair
Registered: Feb, 2006

Re: dice roller Posted: Mar 11, 2006 9:20 PM
Reply to this message Reply
Nevermid, I believe I answered my own question at the bottom there. Two different constructors. What was throwing me off was that I envisioned the printed text as being part of a unified whole, but what I needto see what was it was broken by user input.

Flat View: This topic has 1 reply on 1 page
Topic: need your help Previous Topic   Next Topic Topic: Any Java Source for 16 questions

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use