Java tutor help for trade???

TAB Studio

New member
I will trade mentor inspiration for help or a painted mini just make me a deal....but I really need help with my JAVA class...
Is there anyone out there that programs I have only 2 weeks left of class and it is kicking my ass. I make huge efforts but I get stuck and could use a soft boot please.

For example... right now it is how to handle double ints in a [10][10] array and count the digits occurrences in the 100 random generated number matrix. putty for someone who knows but the count loop with the ints is kicking my butt. I have looked all over the net and will continue and my teacher is not responding.
If anyone has a few bits of time it would be appriciated and favor returned in kind.
 

Tagamoga

New member
Alright...

What do you mean with "double ints" Are you storing double numbers, oder int number in your array? Are they primitive or the generated classes? That means how is your Array definied?

with

int [][]
Integer[][]
double[][] or
Double[][]

After this, what dou really want to count?

Eg:
10, 20, 30
40, 50, 60,
20, 22, 25

Occurences:
0 : seven times
1 : once
2 : five times
3 : once

and so on?

Greetings, Taggi
 

TAB Studio

New member
It is numbers 1-9 but I used the double matrix so they would align better,that was my first mistake.
Yes also I must count how many ones,twos etc occur in the 100 numbers generated and return the information under the matrix


I have this
/*
* Tracy Brady
*/
package countdigits;

public class CountDigits {

public static void main(String[] args){

int[ ][ ] matrix = new int[10][10];



//random numbers * 100
for (int row = 0; row < matrix.length; row++){
for (int column = 0;column < matrix[row].length; column++){
matrix[row][column] = (int)(Math.random() * 10);
}
}
//print array
for (int row = 0; row < matrix.length; row++){
for(int column = 0; column < matrix[row].length; column++){
System.out.print(matrix[row][column] + " ");
}
System.out.println();
}

Now I need to count the number of times each integer shows up and print out the final sum.

I know I need a loop to do it but the brackets are screwing me up
I have tried ...


for (int i =0; i< matrix.length;i++) {
if ( i == 2) {
int counterj = i;

System.out.print("sh*t" + counterj);

I was frustrated I have tried
these approaches also //count array
//
// for (int j =0; j < matrix; j++){
// System.out.println(j);
// }
//numberCounts(matrix);
//displaycounts(matrix);


// public static void numberCounts(int[][] num){
// //array of teh
// int[] []counts = new int[10][10];
// for (int i = 0; i < num.length; i++){
// System.out.print(counts + "fu**");
// }
//
//
// }
//
// public static void displaycounts(int [][] counts){
// for (int i = 0; i < counts.length;i++){
// System.out.print(counts + "sh** ");
//
// if ( i +1<0) {
// System.out.print(counts + "f** ");
// }
//
// else {
// System.out.print(counts + "f** ");
// }
// }




// public static int countNumbers(int[][] arr, int numToFind){
// int countnum=0;
// for (int i = 0; i < arr.length; i++) {
// if (arr == numToFind) {
// countnum++;
// }
// }
// return countnum;
//
// }
// }

// system.out.println(counts + "" + (int)(int+ 1));
// else
// system.out.print(counts + " " + (int) (i + 10)+ "");
// }
//
// }
// public static int find(int[] arr, int numToFind) {
// int occurence=0;
// for (int i = 0; i < arr.length; i++) {
// if (arr == numToFind)
// occurence++;
// return occurence;

I asked my teacher for help...and I sent him this but I forgot to star out the profanities...I am thinking I will not get a quick response even though I apologized for the slip up. I am so frustrated...name your price I have 4 or five chapters more to go and it is not getting any easier.
If we could trade I would be thankful for the help.I have worked at least 18 hours on this silly problem it is not the lack of effort. Thank you for your interest
 
Last edited:

Tagamoga

New member
Ok... i have got it, what you want to do.

For double numbers you can use:
Code:
import java.util.Random;

public class digitis {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        double [][] randomNumbers = new double[10][10]; // preinitialised with 0
        int [] digitCounter = new int [10]; // preinitialised with 0
        
        Random generator = new Random();
        
        // int the random numbers in a range of 0 to 100
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j <10; j++)
            {
                randomNumbers[i][j] = generator.nextDouble()*100;
            }
        }
        
        // for each row do
        for (int i = 0; i < 10; i++)
        {
            // for each number in row do
            for (int j = 0; j <10; j++)
            {
                // parse to String
                String dummy = ""+randomNumbers[i][j];
                // delete all .
                dummy = dummy.replace('.','\u0020');
                // delete all ,
                dummy = dummy.replace(',','\u0020');
                // delete all -
                dummy = dummy.replace('-','\u0020');
                
                // for each digit in dummy do
                for (int k = 0; k < dummy.length(); k++)
                {
                    if (!dummy.substring(k, k+1).equals(" "))
                    {
                        // integer of char:
                        int intDummy = Integer.parseInt(dummy.substring(k, k+1));
                        // rise counter of this digit
                        digitCounter[intDummy]++;
                    }
                }
                
            }
        }
        
        // OutPut:
        for (int i = 0; i < 10; i++)
        {
            System.out.println("Occurences of "+i+" : "+ digitCounter[i]);
        }
        
    }

}
Output like:
Occurences of 0 : 135
Occurences of 1 : 162
Occurences of 2 : 193
Occurences of 3 : 174
Occurences of 4 : 160
Occurences of 5 : 167
Occurences of 6 : 138
Occurences of 7 : 161
Occurences of 8 : 156
Occurences of 9 : 171
For integer number from 0 to 10 it is shorter:
Code:
import java.util.Random;

public class digitis {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        int [][] randomNumbers = new int[10][10]; // preinitialised with 0
        int [] digitCounter = new int [10]; // preinitialised with 0
        
        Random generator = new Random();
        
        // int the random numbers in a range of 0 to 100
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j <10; j++)
            {
                randomNumbers[i][j] =(int)(generator.nextDouble()*10);
            }
        }
        
        // for each row do
        for (int i = 0; i < 10; i++)
        {
            // for each number in row do
            for (int j = 0; j <10; j++)
            {
                digitCounter[randomNumbers[i][j]]++;
            }
        }
        
        // OutPut:
        for (int i = 0; i < 10; i++)
        {
            System.out.println("Occurences of "+i+" : "+ digitCounter[i]);
        }
        
    }

}
Sample output:
Code:
Occurences of 0 : 11
Occurences of 1 : 13
Occurences of 2 : 9
Occurences of 3 : 9
Occurences of 4 : 8
Occurences of 5 : 4
Occurences of 6 : 15
Occurences of 7 : 16
Occurences of 8 : 11
Occurences of 9 : 4
Have fun!

Greetings, Taggi
 

TAB Studio

New member
Tagamoga thank you so very much! Your kindness can not go unacknowledged.
Sorry to haunt you IdofEntity but I oh so needed help. I am on to the next chapter because of her!
 
Back To Top
Top