Question

In: Computer Science

//   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 args[])
   {
       boolean isValid = true;
       int dataRow[] = { 9, 8, 7, 6, 5, 4, 3, 2, 8 };
       }
}

Solutions

Expert Solution

import java.util.*;

public class Soduko_ValidateRow {
        public static void main(String args[]) {
                boolean isValid = true;
                int dataRow[] = { 9, 8, 7, 6, 5, 4, 3, 2, 8 };
                int counter[] = new int[10];
                boolean flag = true;
                for (int i = 0; i < dataRow.length; i++) {
                        if (counter[dataRow[i]] == 0) {
                                counter[dataRow[i]]++;
                        } else {
                                System.out.println("INVALID: Data at index " + i + " is invalid");
                                flag = false;
                                break;
                        }
                        if (dataRow[i] > 9 || dataRow[i] < 1) {
                                System.out.println("INVALID: Data at index " + i + " is invalid");
                                flag = false;
                                break;
                        }
                }
                if(flag)
                        System.out.println("VALID");
        }
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

// Given an int array of size elements, determine if there are k elements that add...
// Given an int array of size elements, determine if there are k elements that add up to sum. // The array holds integers, both positive and negative and zero. // It is not possible to add zero elements (that's when k==0) to any sum, not even zero. // It is not possible to add any elements from an empty array. // Must be recursive and not iterative //bool K_element_sum(size_t k, int sum, int arr[], size_t size){}
Suppose you are given the following array X = [7, 9, 1, 6] Sort the array...
Suppose you are given the following array X = [7, 9, 1, 6] Sort the array in ascending order using the selction sort algorithm. Write the state of the array after each pass. Pass1: Pass2: Pass3: Suppose you are given the following array X = [7, 9, 1, 6] Sort the array in ascending order using the selction sort algorithm. Write the state of the array after each pass. Pass1: Pass2: Pass3:
Given the linear correlation coefficient r and the sample size n, determine the critical values of...
Given the linear correlation coefficient r and the sample size n, determine the critical values of r and use your finding to state whether or not the given r represents a significant linear correlation. Use a significance level of 0.05. r = 0.353, n = 15 A. Critical values: r = ±0.532, no significant linear correlation B. Critical values: r = ±0.514, significant linear correlation C. Critical values: r = ±0.514, no significant linear correlation D. Critical values: r =...
Given the linear correlation coefficient r and the sample size n, determine the critical values of...
Given the linear correlation coefficient r and the sample size n, determine the critical values of r and use your finding to state whether or not the given r represents a significant linear correlation. Use a significance level of 0.05. r = 0.127, n = 15
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?
Please enter a seed: 1 Please enter the size of the array: 1 Array size must...
Please enter a seed: 1 Please enter the size of the array: 1 Array size must be greater than 1. Please reenter: 0 Array size must be greater than 1. Please reenter: -1 Array size must be greater than 1. Please reenter: 12 Please choose an option: 1 Print the array 2 Find the average 3 Find the largest element 4 Count how many times 3 occurred 5 Count how many elements are less than half of the first element...
Given an array A[1..n], with distinct values and k with 1 ≤ k ≤ n. We...
Given an array A[1..n], with distinct values and k with 1 ≤ k ≤ n. We want to return the k smallest element of A[1.....n], in non-decreasing order. For example: A = [5, 4, 6, 2, 10] and k = 4, the algorithm returns [2, 4, 5, 6]. There are at least the following four approaches: a. heapify A and then extract k elements one by one b. sort the array (e.g. using MergeSort or HeapSort) and then read the...
Determine the size of the solar array and the number of batteries required to power a...
Determine the size of the solar array and the number of batteries required to power a pump that will pump water from a 150 ft deep well to a storage tank that is 60-ft above the ground surface. Use the Internet to identify 1) the pump model 2) the solar array kit size and 3) the battery type.
Given an array labeled as array1 with the values: 11111h, 22222h, 33333h, 44444h And another array...
Given an array labeled as array1 with the values: 11111h, 22222h, 33333h, 44444h And another array labeled as array2 with the values: 0AEFFh, 23CAH, 1156H Sum up BOTH arrays through direct addressing and place the sum into the EAX register. array1 is a DWORD and array2 is a WORD
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT