Please help me break down this code

i really need help at understanding this, i put it together a while ago with some help but im really no pro at java but my tutor has asked me to give a break down of the code line by line
/*  This program rolls two six-sided dice a user-specified
number of times, and prints how many times an ordered dice combination occured.
This is followed by a column stating how many times the sum of the two dice
equalled 2 through 12.
import java.util.Scanner;
public class DiceSumDistribution
     public static void main(String[] args)
          Scanner scan = new Scanner(System.in); //receive input from keyboard
          System.out.print("Enter the number of times you would like to toss two dice: "); //prompt user for input
          int timesToToss = scan.nextInt(); //read in user input
          int[] diceSum = new int[37]; //this array holds the dice roll distribution table
          int[] frequencySum = new int[13]; //this array holds how many times a dice sum occured
          int die1, die2; //integers representing the two dice
          for(int i = 0; i < timesToToss; i++) //toss two dice as many times as the user specified
               die1 = (int) (Math.random()*6+1); //assign random number (1 through 6) to dice one
               die2 = (int) (Math.random()*6+1); //assign random number (1 through 6) to dice two
               diceSum[(6*(die1-1))+die2]++; //add one to appropriate cell in distribution table
               frequencySum[die1+die2]++; //add one to appropriate sum counter
          /*the dice roll distribution table shows how many times a certain combination of dice rolls
                  and the rows represent the other dice.
          System.out.println("\n---Dice Roll Distribution Table---");
          System.out.println("\t 1\t2\t3\t4\t5\t6"); //print distribution table
          System.out.println("\t____________________________________________"); //print distribution table
          for(int i = 1; i < 37; i++) //print all 36 cells of distribution tables
               if(i%6 == 1) //if at the beginning of a table row
                    System.out.print(i/6+1 + "\t|"); //print row number
               System.out.print(diceSum[i]+ "\t"); //for each cell in a row, print its value
               if(i%6 == 0) //if at the end of a row
                    System.out.println(); //go down a line
          /*this column represents how many times a sum occured. For example, if the following output occurs
          System.out.println("\n---Dice Roll Sums---");
          for(int i=2; i<=12; i++) //for each possible dice sum
               System.out.println(i+": " + frequencySum); //print each dice sum on its own row
ii wrote this with some help a while ago but i havent done java at all since so im totaly clueless again. if someone could help i would be really greatful, thanks.

ok chill man, and i wasnt asking you to do it for me or nothign liek that.
its mostly these parts im having trouble explaining
Scanner scan = new Scanner(System.in); //receive input from keyboard
          System.out.print("Enter the number of times you would like to toss two dice: "); //prompt user for input
          int timesToToss = scan.nextInt(); //read in user input
die1 = (int) (Math.random()*6+1); //assign random number (1 through 6) to dice one
               die2 = (int) (Math.random()*6+1); //assign random number (1 through 6) to dice two
               diceSum[(6*(die1-1))+die2]++; //add one to appropriate cell in distribution table
               frequencySum[die1+die2]++; //add one to appropriate sum counter
               if(i%6 == 1) //if at the beginning of a table row
                    System.out.print(i/6+1 + "\t|"); //print row number
               System.out.print(diceSum[i]+ "\t"); //for each cell in a row, print its value
               if(i%6 == 0) //if at the end of a row
                    System.out.println(); //go down a linei know in the last one there the "if(i%6 == 1) " and "if(i%6 == 0) " effect the
"System.out.print(i/6+1 + "\t|");" in some way, but i dont really know how to explain it.
thanks

Similar Messages

  • I forgot restrictions cod in ipad air1 and don't off it , please help me for recovery this cod

    i forgot restrictions cod in ipad air1 and don't off it , please help me for recovery this cod...

    Locked Out, Forgot Lock or Restrictions Passcode, or Need to Restore Your Device: Several Alternative Solutions
    A
    1. iOS- Forgotten passcode or device disabled after entering wrong passcode
    2. iPhone, iPad, iPod touch: Wrong passcode results in red disabled screen
    3. Restoring iPod touch after forgotten passcode
    4. What to Do If You've Forgotten Your iPhone's Passcode
    5. iOS- Understanding passcodes
    6. iTunes 10 for Mac- Update and restore software on iPod, iPhone, or iPad
    7. iOS - Unable to update or restore
    Forgotten Restrictions Passcode Help
                iPad,iPod,iPod Touch Recovery Mode
    You will need to restore your device as New to remove a Restrictions passcode. Go through the normal process to restore your device, but when you see the options to restore as New or from a backup, be sure to choose New.
    You can restore from a backup if you have one from BEFORE you set the restrictions passcode.
    Also, see iTunes- Restoring iOS software.
    And also see How to Recover Forgotten iPhone, iPad Restrictions Passcode.

  • Please help me to complete this code

    import java.security.MessageDigest;
    import java.util.Map;
    import java.util.Scanner;
    public class PasswordService
       //The hash is to be formed using the SHA algorithm
       //to create a MessageDigest
       private final String algorithmName = "SHA";
       //Use a message digest to create hashed passwords
       private MessageDigest md = null;
       //We simulate a database of users using who have a login and password
       //as a key and value pair in a Map
       private Map<String, byte[]> userData;
       //complete the constructor
       public PasswordService()
         //TODO - intialize the class instance data
          //some dummy data - do not alter these lines
          addUser("daddy", "cool");
          addUser("nightflight", "topChat");
          addUser("boney", "2E5sxuSRg6A");
       public void showProvider()
          //TODO
       //Get the hash value for the provided string password.
         public byte[] getHash(String password)
          //TODO
          return null;
       public void addUser(String login, String password)
          //TODO
       public byte[] getPassword(String login)
          //TODO
          return null;
       public boolean checkLogin(String login, String password)
         // TODO
          return false;
       //This method is provided to perform a login from the command line
       public boolean doLogin()
          Scanner sc = new Scanner(System.in);
          System.out.println("Enter login please");
          String login = sc.next();
          System.out.println("Your password please");
          String password = sc.next();
          return checkLogin(login, password);
       public static void main(String[] args)
          int attempts = 0;
          showProvider();
          while(attempts < 4)
             boolean match = doLogin(); //request login and password
             System.out.println("match? " + match);
             attempts++;
    }

    please help me to complete this code
    void completeCode(Code code,Properties options) throws CodeCompletingException
    CodeCompleterFactory cf = CodeCompleterFactory.newInstance();
    CodeCompleter cc = cf.newCodeCompleter();
    cc.complete(code,options);
    }

  • Can you please help me improve on this code

    Here is code for a drag and drop activituy where there are 4 questions, each question is on a separate frame of a movieclip mentorquestions.  I am trying to have the frame picked at random and then have either the yes target or the no target visible for the right answer to correspond with the question. yesplay is a little animation to let you know you got the correct answer.   My code is a bit hit and miss I think.. I am doing something (or many things) wrong
    any suggestions?
    cheers
    sub
    import flash.events.MouseEvent;
    yesplay.addEventListener(Event.ENTER_FRAME, checkit);
    function checkit (myevent:Event):void {
            if (yesplay.currentFrame == 27)
            {reset1();
    var incorrect:Number=0;
    var correct:Number=0;
    targetYes.visible=false;
    targetNo.visible=false;
    var Qmove:Array = [1,2,3,4];
    var b:Number=4;
    var a:Number;
    var c:Number;
    function pickquestion(){
              a=Math.floor(Math.random() * b);
              mentorquestions.gotoAndStop(Qmove[a]);
              c=Qmove[a];
              trace(c);
              setanswer();
              Qmove.splice(a,1);
              b=b-1;
              trace(a);
              trace(Qmove);
              trace(b);
    pickquestion();
    function setanswer(){;
              if (c==3){
                        targetYes.visible=true;
                        targetNo.visible=false;
              }else{
                        targetYes.visible=false;
                        targetNo.visible=true;
    AbackBT.addEventListener(MouseEvent.CLICK, Abacker);
    function Abacker(e:MouseEvent){
              visible=false;
    var Yx:Number=843;
    var Yy:Number=295;
    var Nx:Number=843;
    var Ny:Number=394;
    function reset1(){
              yes.x=Yx;
              yes.y=Yy;
              no.x=Nx;
              no.y=Ny;
              pickquestion();
    var startX:Number;
    var startY:Number;
    this.yes.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);
    this.yes.addEventListener(MouseEvent.MOUSE_UP,dropMe);
    function pickMe(event:MouseEvent):void {
        event.target.startDrag();
              startX = event.target.x;
        startY = event.target.y;
    function dropMe(event:MouseEvent):void {
        event.target.stopDrag();
              var myTargetName:String = "yes" + event.target.name;
    if (event.target.dropTarget != null && event.target.dropTarget.parent == targetYes){
            event.target.x = targetYes.x;
            event.target.y = targetYes.y;
                        yesplay.play();
    }else{
              event.target.x = startX;
        event.target.y = startY;
              wrongun.play();
    this.yes.buttonMode = true;
    this.no.addEventListener(MouseEvent.MOUSE_DOWN, pickMe1);
    this.no.addEventListener(MouseEvent.MOUSE_UP,dropMe1);
    function pickMe1(event:MouseEvent):void {
        event.target.startDrag();
              startX = event.target.x;
        startY = event.target.y;
    function dropMe1(event:MouseEvent):void {
        event.target.stopDrag();
                        var myTargetName:String = "no" + event.target.name;
    if (event.target.dropTarget != null && event.target.dropTarget.parent == targetNo){
            event.target.x = targetNo.x;
            event.target.y = targetNo.y;
                        yesplay.play();
    }else{
              event.target.x = startX;
        event.target.y = startY;
              wrongun.play();
    this.no.buttonMode = true;

    You'll need to be more specific with presenting your problems insteasd of just putting up a bunch of code and asking others to fix it for you.  Try to keep what you present focused on a specific problem.

  • Please help me with modifying this code

    I am using the attached code to acauire and save data to a text file, using 'write measurement file' express VI.
    WHat I want to do is to replace 'write to measurement VI' with low-level file I/O VIs. I tried to convert the express VI, but the obtained code is too complicated.
    Anyone can give me hints for using file I/O Vis to implement same function without using the express VI? Thanks a lot.
    Message Edited by Dejun on 08-27-2007 11:26 AM
    Attachments:
    4.png ‏14 KB
    code.vi ‏121 KB

    Above code is in a case of an event structure, i.e., each time I click a buttom, such as 'RUN', data acquisition begins and write data into a file.
    What I want is, each time this event case is executed, a file is open, write data to it, and finally close this file. The next time when I run this case, maybe another file is open for writting data.
    The problem of using 'write measure file' express VI is: if a file is open in one execution of the case, it will continuously be in 'open' after this case execution is finished, i.e., there is no explicit close file function with the express VI, which in some cases may be a problem. What I need is closing the file at the end of each execution of a event case. With low-level file I/O VIs, maybe I can directly put a close file VI there.
    The data file should be in text format so that data analysis software, such as MS-powerpoint, can directly reads it.
    Message Edited by Dejun on 08-27-2007 01:55 PM
    Message Edited by Dejun on 08-27-2007 01:56 PM

  • Please help me to solve this date comparision issue..

    Please help me to solve this issue..
    If i have some data like the following..
    ID           START DATE             END DATE
    1             20080101              20080501
    1             20080502              20080630
    2             20080631              20080801
    2             20080802              20080901
                                                 ---------------> There is a break in date over here
    2             20080930              20081029
    2             20081030              20081130
    I need to compare the End Date with the start date (These data will not be in order)
    and find out if there is any break and should get the output date : *20080930*
    I am trying to do this in SQL or PL/SQL.Please help me .
    Thanks in advance.
    phani

    Hi Frank ,
    Sorry to bug you again. I ran your code on my actual data but not gettting the expected output.Here i am posting the actual code and the output that i got when i ran your code.Please bear with me and help me to solve this..
    /* Formatted on 5/25/2009 2:27:24 PM (QP5 v5.115.810.9015) */
    SELECT   member_nbr,
             aff_nbr,
             ymdeff,
             ymdend,
             gap_before,
             COUNT (gap_after)
                OVER (PARTITION BY member_nbr, aff_nbr ORDER BY ymdend DESC)
                AS gap_cnt
      FROM   (SELECT   member_nbr,
                       aff_nbr,
                       ymdeff,
                       ymdend,
                       CASE
                          WHEN ymdeff >
                                  LEAD(ymdend)
                                     OVER (PARTITION BY member_nbr, aff_nbr
                                           ORDER BY ymdend DESC)
                                  + 1
                          THEN
                             1
                       END
                          AS gap_before,
                       CASE
                          WHEN ymdend <
                                  LAG(ymdeff)
                                     OVER (PARTITION BY member_nbr, aff_nbr
                                           ORDER BY ymdend DESC)
                                  - 1
                          THEN
                             1
                       END
                          AS gap_after
    ------------I need this SQL to filter the whole data to the data that i posted in previous post -----
                FROM   (  SELECT   ms1.member_nbr, 
                                   ms1.aff_nbr,
                                   ms1.ymdeff,
                                   ms1.ymdend,
                                   ms1.void
                            FROM   (SELECT   ms.member_nbr,
                                             ms.aff_nbr,
                                             ms.ymdeff,
                                             ms.ymdend,
                                             ms.void
                                      FROM   MEMBER mb, member_span ms
                                     WHERE   mb.member_nbr = ms.member_nbr
                                             AND (20090523 BETWEEN ms.ymdeff
                                                               AND  ms.ymdend
                                                  AND TRIM (void) IS NULL)
                                             AND mb.member_nbr = 'A1000073000 ')
                                   eff_pcp,
                                   member_span ms1
                           WHERE   ms1.member_nbr = eff_pcp.member_nbr
                                   AND (SUBSTR (eff_pcp.aff_nbr, 1, 6) =
                                           SUBSTR (ms1.aff_nbr, 1, 6))
                        ORDER BY   ms1.ymdeff DESC)
    ---------- end of my part  ----------
                table_x) got_gaps;Outputs that i got when i ran that code for each individual members..
    Sorry to bug you frank and thanks for all the help.I will post here if i get any other data.
    Thanks
    phani

  • Please help to re-write this query using exists or with

    Hi please help to re-write this query using exists or with, i need to write same code for 45 day , 90 days and so on but sub query condition is same for all
    SELECT SUM (DECODE (t_one_mon_c_paid_us, 0, 0, 1)) t_two_y_m_mul_ca_
    FROM (SELECT SUM (one_mon_c_paid_us) t_one_mon_c_paid_us
    FROM (
    SELECT a.individual_id individual_id,
    CASE
    WHEN NVL
    (b.ship_dt,
    TO_DATE ('05-MAY-1955')
    ) >= SYSDATE - 45
    AND a.country_cd = 'US'
    AND b.individual_id in (
    SELECT UNIQUE c.individual_id
    FROM order c
    WHERE c.prod_cd = 'A'
    AND NVL (c.last_payment_dt,
    TO_DATE ('05-MAY-1955')
    ) >= SYSDATE - 745)
    THEN 1
    ELSE 0
    END AS one_mon_c_paid_us
    FROM items b, addr a, product d
    WHERE b.prod_id = d.prod_id
    AND d.affinity_1_cd = 'ADH'
    AND b.individual_id = a.individual_id)
    GROUP BY individual_id)
    Edited by: user4522368 on Aug 23, 2010 9:11 AM

    Please try and place \ before and after you code \Could you not remove the inline column select with the following?
    SELECT a.individual_id individual_id
         ,CASE
            when b.Ship_dt is null then
              3
            WHEN b.ship_dt >= SYSDATE - 90
              3
            WHEN b.ship_dt >= SYSDATE - 45
              2
            WHEN b.ship_dt >= SYSDATE - 30
              1
          END AS one_mon_c_paid_us
    FROM  items           b
         ,addr            a
         ,product         d
         ,order           o
    WHERE b.prod_id       = d.prod_id
    AND   d.affinity_1_cd = 'ADH'
    AND   b.individual_id = a.individual_id
    AND   b.Individual_ID = o.Individual_ID
    and   o.Prod_CD       = 'A'             
    and   NVL (o.last_payment_dt,TO_DATE ('05-MAY-1955') ) >= SYSDATE - 745
    and   a.Country_CD    = 'US'

  • Please help me in doing this

    hi,
    I'm new for the JSP and got struck at this point .
    I have a JSP page wherein it consists of a table and the servlet that retrieves the data from the DB(MY SQL). Now i need to fill the contents of the table as mentioned below.
    First 5 rows must get printed then upon clicking the next button the next five rows must be filled.....and so on......
    Please help me in reaching this requirement.
    JSP CODE:
    <%@ page import="java.io.*" %>
    <%@ page import="java.lang.*" %>
    <%@ page import="java.util.*" %>
    <html>
    <head><title> TOP USERS </title>
    </head>
    <body bgcolor="c0c0c0">
    <div align="center">
    <table>
    <tr bgcolor="white"><td> <font color="red" size="5"><b>TOP  USERS </b> </font></td></tr>
    </table>
    </div>
    <div align="center">
    <form name="top">
    <font face="verdana">
    Report for TOP
    <select name="users">
    <option value="5">5
    <option value="10">10
    <option value="15">15
    </select>
    Users
    <br> <br>
    <% ArrayList list=new ArrayList();
    list=(ArrayList)request.getAttribute("TOPUSERS");
    %>
    <table border="1" align="center" width=35%>
    <tr>
      <td align="center"><b> Name </b> </td>
      <td align="center"> <b> Phone # </b> </td>
    </tr>
    <%
      int cnt=10;
      if(cnt!=0)
      for(int i=0; i<cnt; i++)
    %>
    <tr>
    <td align="left"> <% out.println(list.get(i));
                         i++; %>
    </td>
    <td align="right"> <% out.println(list.get(i));%>
    </td>
    </tr>
    <% }
      }  %>
    </table>
    <table border="0" align="center" width=35% >
    <tr><td align="right"> <input type="submit" value="next" name="next" onclick="return cnt+=10"> </td> </tr>
    </table>
    </font>
    </form>
    </div>
    </body>
    </html>Please correct the above code......
    sorry if my code is wrong........
    Here i can print the all the rows at once but i'm not able to pring in 5 rows and upon the clik of next the next five rows........

    Pass it as a hidden parameter.

  • My ipad air getting close all apps automatically within seconds while connecting wifi. This issue is started after the updation of the iSO 8, Please help me to rectify this issue.

    Hi,
    My ipad air getting close all apps automatically within seconds while connecting wifi. This issue is started after the updation of the iSO 8, Please help me to rectify this issue.
    Expecting some quick solution in this regard,
    Thanks
    Prabhu

    (A) Try reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.
    (B) Try reset all settings
    Settings>General>Reset>Reset All Settings
    Note: Data will not be affected but settings for Wi-Fi, FaceTime, Message, Home Sharing will be reset

  • Hi, I have recently updated my iMac from OS x mountain lion to OS X Mavericks. After that I can't upload any video and some files to my personal email account. Can anyone please help me to sort this problem.

    Hi,
    I have recently updated my iMac from OS x mountain lion to OS X Mavericks.
    After that I can't upload any video and some files to my personal email account.
    I have tried to send a small video clip to the sender as attachment. i have done this before
    with the same video same and same email account. This problem found just after installed the
    OS X Movericks. Can anyone please help me to sort this problem.
    Thanks.
    Roman

    Please follow these directions to delete the Mail "sandbox" folders. In OS X 10.9 there are two sandboxes, while in earlier versions there is only one.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Containers/com.apple.mail
    Right-click or control-click the highlighted line and select
    Services ▹ Reveal
    from the contextual menu.* A Finder window should open with a folder named "com.apple.mail" selected. If it does, move the selected folder — not just its contents — to the Desktop. Leave the Finder window open for now.
    Log out and log back in. Launch Mail and test. If the problem is resolved, you may have to recreate some of your Mail settings. You can then delete the folder you moved and close the Finder window. If you still have the problem, quit Mail again and put the folder back where it was, overwriting the one that may have been created in its place. Repeat with this line:
    ~/Library/Containers/com.apple.MailServiceAgent
    Caution: If you change any of the contents of the sandbox, but leave the folder itself in place, Mail may crash or not launch at all. Deleting the whole sandbox will cause it to be rebuilt automatically.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combinationcommand-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar, paste into the box that opens (command-V). You won't see what you pasted because a line break is included. Press return.

  • My iPhone 6 ear speaker is not working properly I couldn't able to hear any thing from ear speaker to lissen I had to put on loud speaker or to use handsfree please help me out with this problem if some body have answer?

    My iPhone 6 ear speaker is not working properly I couldn't able to hear any thing from ear speaker to listen I had to put on loud speaker or to use hands free please help me out with this problem if some body have answer?

    Hi Venkata from NZ,
    If you are having an issue with the speaker on your iPhone, I would suggest that you troubleshoot using the steps in this article - 
    If you hear no sound or distorted sound from your iPhone, iPad, or iPod touch speaker - Apple Support
    Thanks for using Apple Support Communities.
    Best,
    Brett L 

  • I have problem with account that i can't make update or buy from app store There is massage appear in my payment page that i must contact with i tunes support to complete this transaction Please help me to fixe this problem as soon possible Hany hassan 00

    I have problem with account that i can't make update or buy from app store
    There is massage appear in my payment page that i must contact with i tunes support to complete this transaction
    Please help me to fixe this problem as soon possible
    Hany hassan
    0096597617317
    0096596677186
    Thank you

    You need to Contact iTunes Support...
    Apple  Support  iTunes Store  Contact Us

  • I have unabled 5 fingure gesture now not able to perform any task,also my power button is not working,please help me in removing this gesture,using I phone 4

    I have unabled 5 fingure gesture now not able to perform any task,also my power button is not working,please help me in removing this gesture,using I phone 4

    I have unabled 5 fingure gesture now not able to perform any task,also my power button is not working,please help me in removing this gesture,using I phone 4

  • Hello i have a unusual problem,anyway my iphone 4 wont turn on and when someone calls they hear ringing,but my phone doesent ring,so i open cimcas now ring off. Screen is just black,because it's turned off..Please help me to solve this problem..Thanks

    Hello i have a unusual problem,anyway my iphone 4 wont turn on and when  someone calls they hear ringing,but my phone doesent ring.So i poen simcase and now ring off. Screen is just  black,because it's turned off..Please help me to solve this  problem..Thanks

    As far as trying to power up your device, make sure it has a good charge and then hold the button on the top of the phone and the home button on the faceplate together until the apple appears on the screen.

  • Hi, when ever I'm using 3G, on my Iphone4 sim stops working and Network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem.

    Hi, when ever I'm using 3G, on my Iphone4 sim stops working and network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem. Thanks.

    Photos/videos in the Camera Roll are not synced. Photos/videos in the Camera Roll are not touched with the iTunes sync process. Photos/videos in the Camera Roll can be imported by your computer which is not handled by iTunes. Most importing software includes an option to delete the photos/videos from the Camera Roll after the import process is complete. If is my understanding that some Windows import software supports importing photos from the Camera Roll, but not videos. Regardless, the import software should not delete the photos/videos from the Camera Roll unless you set the app to do so.
    Photos/videos in the Camera Roll are included with your iPhone's backup. If you synced your iPhone with iTunes before the videos on the Camera Roll went missing and you haven't synced your iPhone with iTunes since they went missing, you can try restoring the iPhone with iTunes from the iPhone's backup. Don't sync the iPhone with iTunes again and decline the prompt to update the iPhone's backup after selecting Restore.

Maybe you are looking for