Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Simple Java program 2


use file As a practical joke for your birthday, your best friend gave you some single- dimensioned arrays, each full of boolean values. She didn’t tell you how many items are stored in these arrays. As if that weren't bad enough, your friend told you that each array is filled almost entirely with false values, except for a small sequence of consecutive trues contained somewhere in the array. Overwhelmed by the novelty of all this, you decided (actually, we've decided for you) to write a static Java method named fullOfBool that accepts an array of boolean values as its only argument, and will print out the location of the first true in the boolean array the location of the last true in the boolean array the total number of true values in the string of consecutive true values. Your main method should call on fullOfBool using the following arrays to test it out: boolean [] test1 = { false, true, true, true } ; boolean [] test2 = { true } ; boolean [] test3 = { true, true, true, true, false } ; Attachments
Tags Clarifications


Simple Java program 2 - Solution


Below is the solution for the Bool assignment. Attachments (1 K) Download Preview
boolean array is located at position: " + count); } static private void findTotalNrOfConsecutiveTrue(boolean[] array) { int total = 1; for (int i = 0; i < array.length - 1; i++) { if (array[i] && array[i] == array[i + 1]) { total++; } else if (total > 1 && !array[i])

Purchase Answer