Question

In: Computer Science

I have an 8 by 8 array that has values ranging from 1-64. I am wanting...

I have an 8 by 8 array that has values ranging from 1-64. I am wanting to display the array evenly but due to some digits being single and others double, it displays lopsided. What would be the best way to get everything in the array to display in a nice even square?

Solutions

Expert Solution

CODE IN JAVA:

Square.java file:

public class Square {
   public static int digitCount(int n) {
       int count = 0 ;
       while(n!=0) {
           n = n/10 ;
           count += 1 ;
       }
       return count ;
   }
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int arr[][] = new int[8][8];
       int count = 1 ;
       for(int i=0;i<8;i++) {
           for(int j=0;j<8;j++) {
               arr[i][j] = count ;
               count +=1 ;
           }
       }
       for(int i=0;i<8;i++) {
           for(int j=0;j<8;j++) {
               System.out.print(" "+arr[i][j]+" ");
               if(digitCount(arr[i][j])==1)
                   System.out.print(" ");
           }
           System.out.println("");
       }
   }

}
OUTPUT:


Related Solutions

Suppose we have a die that has face values ranging from 2 to 12. This can...
Suppose we have a die that has face values ranging from 2 to 12. This can be represented as a uniform random variable. (a) Find the probability of rolling a 4. (b) Find the expected value of any roll. (c) Find the standard deviation of the roll.
I am creating a crop watering "simulator" in Python. I have the user input an array...
I am creating a crop watering "simulator" in Python. I have the user input an array and then must compare the placement of water and crops to determine if all the crops in the array are watered. The user will either input a "w" for water or "c" for crop when creating the array. A w cell can water 8 cells around it, including itself. My end result must determine if all the crops will be watered or not. How...
JAVA JAVA JAVA JAVA, My array has 1000 int variables with random values from 1-100, I...
JAVA JAVA JAVA JAVA, My array has 1000 int variables with random values from 1-100, I want to be able to scan and output which number appears the most and the least. int x =1000 int[] array = new array[x] for(int i = 0 ; i < x; i++){ array[i] = random.nextInt(101); }
1) Define and create an array of integers with the values 5, 7, 8, 9 10,...
1) Define and create an array of integers with the values 5, 7, 8, 9 10, 12 using an initializer list. Print the array. 5. 2) Given the Array below, replace the element at position 3 with the value, 99, using an assignment statement. int [] list = {88, 0, 11, 22, 55, 77}; What is the value of list.length?
1)As an employee list 8 expectations you have from your employer 2)As am employer list 8...
1)As an employee list 8 expectations you have from your employer 2)As am employer list 8 expectation you would have of your employee 3)What is considered Full Time Hours in Canada and Japan? 4)What is considered Part Time Hours in Canada and Japan? 5)What would you do if you felt something was unsafe at work? 150 words
Suppose we have N = 6 values from a population. These values are 4, 8, 0,...
Suppose we have N = 6 values from a population. These values are 4, 8, 0, 10, 14 and 6. Let μ and σ denote the population mean and population standard deviation of these six values, respectively. (a) What are the values of μ and σ, respectively? μ = 4.8580; σ = 7 μ = 7; σ = 4.8580 μ = 7; σ = 4.4347 μ = 7; σ = 19.6667 μ = 7; σ = 23.6 (b) What percentage...
//   Given an array of size 9, with the values of 1-9, determine if the array...
//   Given an array of size 9, with the values of 1-9, determine if the array //   is valid or not. //   Display a message stating the row is VALId, or state its INVALID and what //   was the index number that determined the data invalid. // //   Use this java code as a start of your code. //   Test the array data by changing the values. //============================================================================= import java.util.*;    public class Soduko_ValidateRow    { public static void main(String...
I have the problem in bold below. I am completely confused. I am hoping that I...
I have the problem in bold below. I am completely confused. I am hoping that I will see how you did this and will be able to follow it. Please remember that I have just started this so please don't use any complex features that an absolute beginner (like me) wouldn't know. Additional information:   /*This is what everyone owes before tax and tip:     Person 1: $10     Person 2: $12     Person 3: $9     Person 4: $8     Person 5: $7     Person 6:...
in C i have a 2d array char m[8][8] = {{1,1,1,1,1,1,1,1}, {1,0,0,0,1,0,0,1}, {1,0,1,0,1,1,0,1}, {1,0,1,0,0,0,0,1}, {1,0,1,1,1,1,0,1}, {1,0,0,0,0,0,0,1},...
in C i have a 2d array char m[8][8] = {{1,1,1,1,1,1,1,1}, {1,0,0,0,1,0,0,1}, {1,0,1,0,1,1,0,1}, {1,0,1,0,0,0,0,1}, {1,0,1,1,1,1,0,1}, {1,0,0,0,0,0,0,1}, {1,0,1,0,1,0,1,1}, {1,1,1,1,1,1,1,1}} turn this array into a 8 integer array int new[8]={-1,-119,-83, ......} i.e Two's Complement to integer 10001001 --> -119
I am working on creating a Wiebull distribution from a large set of data I have....
I am working on creating a Wiebull distribution from a large set of data I have. Everything I find online says that I should be given the shape parameter (beta), and scale parameter (eta/apha). I do not have these numbers and I am not sure how to find them to accurately create a Weibull dist.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT