Jump to content

SlaughterApollo

Member
  • Posts

    25
  • Joined

  • Last visited

Awards

This user doesn't have any awards

SlaughterApollo's Achievements

  1. I finally resolved it after completely rethinking it. import java.util.Scanner;public class P_NumChecks { public static void main(String[] args){ Scanner s = new Scanner(System.in);System.out.println("Enter number of elements in the array followed by the values with each separated by a space");int size = s.nextInt();int[] nums = new int[size];for(int x = 0; x < nums.length; x++) nums[x] = s.nextInt();System.out.println("Enter the integer number to compare array against:");int value = s.nextInt();boolean[] checks = buildBoolean(value, nums);outputArray(checks, nums);} private static void outputArray(boolean[] checks, int[] nums) { String[] output = new String[nums.length]; int t = 0; int f = 0; for(int y = 0; y < nums.length; y++){ if(checks[y]){ t++; output[y] = "T"; } else{ f++; output[y] = "F"; } } if(t == nums.length) System.out.println("All " + nums.length + " true"); else if(f == nums.length) System.out.println("All " + nums.length + " false"); else{ for(int y = 0; y < nums.length; y++){ System.out.print(output[y]); } } } public static boolean[] buildBoolean(int value, int [] nums){ boolean[] temp = new boolean[nums.length]; //String[] output = new String[nums.length]; System.out.println("Expected Output:"); for(int y = 0; y < nums.length; y++){ if(nums[y] > value) temp[y] = true; else temp[y] = false; } return temp; }}
  2. This is the problem I have word for word. The lab is called P_NumCheck. It requires you to write two methods. The first is buildBoolean. This method receives an interger value and an array of integers. It builds a boolean array of the same size as the integer array. The elements in the boolean array are determined by whether or not the corresponding values in the integer array are bigger than the integer value sent into the array. If they are bigger than the integer true is assigned at that index in the boolean array. If the element is less than or equal to the integer value false is assigned. The second method is called outputArray. It simply processes the boolean array and outputs T for all the true values and F for all the false values. If all of the values are true, it will output "All <num> true" instead the contents of the array, where num is the number of elements in the arrary. If all of the values are false it will output " All <num> false". SAMPLE OUTPUT: Enter number of elements in the array followed by the values with each separated by a space 5 6 7 8 9 10 Enter the integer number to compare them against: 8 Expected Output: FFFTT SAMPLE OUTPUT 2: Enter number of elements in the array followed by the values with each separated by a space 4 7 12 9 11 Enter the integer number to compare them against: 2 Expected Output: All 4 true We were provided with a main method to use on the program which is as followspublic static void main(String[] args){ Scanner s = new Scanner(System.in); System.out.println("Enter number of elements in the array followed by the values with each separated by a space"); int size = s.nextInt(); int[] nums = new int[size]; for(int x = 0; x < nums.length; x++) nums[x] = s.nextInt(); System.out.println("Enter the integer number to compare array against:"); int value = s.nextInt(); boolean[] checks = buildBoolean(value, nums); outputArray(checks);} And this is the program that I have written import java.util.Scanner;public class P_NumChecks { public static void main(String[] args){ Scanner s = new Scanner(System.in);System.out.println("Enter number of elements in the array followed by the values with each separated by a space");int size = s.nextInt();int[] nums = new int[size];for(int x = 0; x < nums.length; x++) nums[x] = s.nextInt();System.out.println("Enter the integer number to compare array against:");int value = s.nextInt();boolean[] checks = buildBoolean(value, nums);outputArray(checks, size);} public static boolean[] buildBoolean(int value, int [] nums){ boolean [] tempArray = new boolean[nums.length]; for(int x = 0; x < nums.length; x++ ){ if(nums[x] > value){ tempArray[x] = true; } else if(nums[x] <= value){ tempArray[x] = false; } } return tempArray; } public static void outputArray(boolean[] checks, int size) { int t = 0; int f = 0; System.out.println("Expected Output:"); for(int x = 0; x < checks.length; x++){ if(checks[x] = true){ t++; if(t > size){ System.out.println(" All " + (size) + " True"); } if(checks[x] = false){ f++; if(f > size){ System.out.print(" All " + (size) + " false"); } else if(f <= size){ System.out.print("F"); } } else if(t <= size){ System.out.print("T"); } } } } } Clearly it doesn't work property. Please provide me with a working example and why it does not work. Try not to use any means of code that is too advanced compared to what you see above.
  3. i got the math but the spacing is messing me up public class Chp4_19 { public static void main(String[] args) { for(int x = 0; x < 8; x++) { for(int y = 8 - x; y> 0; y--) { System.out.print(" "); } int w = 1; for(int z = 0; z < x; z++) { System.out.print(w + " "); w = w * 2; } while(w>0) { System.out.print(w + " "); w = w / 2; } System.out.println(); } }}
  4. I'm having a small issue with a program from school. I need to use a nested for loop (A for loop inside another) to output the following. Any help is greatly appreciated 1 1 2 1 1 2 4 2 1 1 2 4 8 4 2 1 1 2 4 8 16 8 4 2 1 1 2 4 8 16 32 16 8 4 2 1 1 2 4 8 16 32 64 32 16 8 4 2 1 1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
  5. I'm trying to make a program for school and i was wondering if it is possible in a while loop or some kind of loop if u can create a unique variable for the each integer value intputted?
  6. a little explanation please?
  7. Doing my last minute summer homework for my AP computer science class and I need a little help. I need to output in the console strictly a b pow( a , b ) 1 2 1 2 3 8 3 4 81 And so one. This would be a breeze for me in visual basic but im very new with java can someone help me out?
  8. Ok so exactly what kind of picture are you asking for because the ones i can take with my pc running arent really special
  9. Also the back USB 2.0 slots work perfectly otherwise i would not by typing this or using a mouse lol
  10. The USB 3.0 in this case is black but it is plugged in and it is plugged in correctly along with the usb 2.0 i have checked that multiple times
  11. What is your power consumption compared to how much power your PSU can put out? That may be it...
×