Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 856111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:11:16+00:00 2026-05-15T08:11:16+00:00

Under the addRolls method I need to populate the nums array with the frequency

  • 0

Under the addRolls method I need to populate the nums array with the frequency of the ‘total’ variable numbers. These method adds the two dice rolls together properly and stores it in the ‘total’ variable but I cannot seem to properly throw them into an array that does the frequency such as the method above it – indFreq. In case that’s hard to follow I think this might make more sense : It’s just the addRolls method that needs to be looked at I believe. It needs to return an array with the frequency of the ‘total’ numbers.

import java.util.Scanner; 
public class Project2 {


public static void main( String[] args )
{
    Scanner inp = new Scanner( System.in );
    int matrix [][]=new int[100][2];

    System.out.print("Press 'q' to exit or 'enter' to continue: \t");
    String response =inp.nextLine();

    while ( !response.toLowerCase().equals("q") ){             
        for (int row=0;row<matrix.length;row++){
            for (int column=0;column<matrix[row].length;column++)
                matrix[row][column]=diceRoll();
        }

        int [] hist1=indFreq(matrix);
        int [] roll=addRolls(matrix);

        for (int i=1;i<hist1.length;i++){
            String star=starPrint(hist1[i]);
            System.out.print(" \n" +hist1[i]+ star);
        }
        System.out.println("");
        //  } 

        System.out.print("\n\nPress 'q' to exit or 'enter' to run again:\t");
        response =inp.nextLine();
    }       
}

public static int diceRoll(){
    int num=(int)(Math.random()*6+1);
    return num;
}

public static String starPrint(int value){
    String star= "";
    for (int i=0;i<value;i++){
        star +="*";
    }
    return star;
}

public static int [] indFreq(int [][] matrix){
    int [] nums =new int[7];

    for (int i=0;i<matrix.length;i++){          
        for (int j=0; j<matrix[i].length;j++)     
            nums[matrix[i][j]] += 1;                 
    }
    return nums;
}

public static int [] addRolls(int [][] matrix){
    int total= 0;
    int[]nums=new int[13];

    //Adds the rows together.
    for (int i=0;i<matrix.length;i++){
        total=0;
        for (int j=0;j<matrix[i].length;j++)   
            total+=matrix[i][j];  
    }
    return nums;    
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:11:17+00:00Added an answer on May 15, 2026 at 8:11 am
        //Adds the rows together. 
        for (int i=0;i<matrix.length;i++){ 
            total=0; 
            for (int j=0;j<matrix[i].length;j++)    
                total+=matrix[i][j]; 
            nums[total]++;
        } 
    

    have you tried this?

            for (int i=1;i<roll.length;i++){ 
                String star=starPrint(roll[i]); 
                System.out.print("\n" + i+ " : " +roll[i] + " " + star); 
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Under TFS 2010, I need to populate the "Found in" control on the Bug
Under what circumstances would java.util.zip.ZipFile.close() throw an IOException? Its method signature indicates that it
Under what circumstances is it unsafe to have two different threads simultaneously writing to
Under normal circumstances, a VB.NET application of mine can check the ClientName environmental variable
Under certain situations, I need to evict the oldest element in a Java Set
Under what circumstance would you use field variable instead of local variable? I found
Under Ubuntu 10, I installed using: npm install js2coffee Seems to install smoothly I
Under what specific situation is it ok (or even recommended) to present end-users with
Under Windows 7 I have a batch file for checking the status of some
Under the .NET Compact Framework, there is no FormWindowState.Minimize value. How can I minimize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.