Jump to content

%_%

Members
  • Posts

    3
  • Joined

  • Last visited

Recent Profile Visitors

3,356 profile views

%_%'s Achievements

Newbie

Newbie (1/14)

  1. It appears that in your sql query you are missing the variable tbl_name. I would try putting that in an seeing if you still get the same error
  2. My solution in java public class PowerSet { public static void main(String[] args) { Object[] set = {1,2,3};//change to whatever variable type LinkedHashSet myPowerSet = powerset(set); System.out.println(myPowerSet.toString()); } /** * Returns the power set from the given set by using a binary counter * Example: S = {a,b,c} * P(S) = {[], [c], [b], [b, c], [a], [a, c], [a, b], [a, b, c]} * @param set Obect[] * @return LinkedHashSet */ private static LinkedHashSet powerset(Object[] set) { //create the empty power set LinkedHashSet power = new LinkedHashSet(); //get the number of elements in the set int elements = set.length; //the number of members of a power set is 2^n int powerElements = (int) Math.pow(2, elements); for (int i = 0; i < powerElements; i++) { String binary = binaryValue(i, elements); LinkedHashSet innerSet = new LinkedHashSet(); for (int j = 0; j < binary.length(); j++) { if (binary.charAt(j) == '1') { innerSet.add(set[j]); } } power.add(innerSet); } return power; } /** * Converts the given integer to a String representing a binary number * with the specified number of digits * For example when using 4 digits the binary 1 is 0001 * @param binary int * @param digits int * @return String */ private static String binaryValue(int binary, int digits) { String temp = Integer.toBinaryString(binary); int foundDigits = temp.length(); String returner = temp; for (int i = foundDigits; i < digits; i++) { returner = "0" + returner; } return returner; } }
  3. Below is a copy of my solution. import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class FileToByteArray { private File file; public FileToByteArray(File file) { this.file = file; } private byte[] firstHalf; private byte[] secondHalf; public byte[] getBytesFromFile() throws IOException { InputStream is = new FileInputStream(file); long length = file.length(); if (length > Integer.MAX_VALUE) { // the file is to large return null; } // Create the byte array to hold the data byte[] bytes = new byte[(int) length]; firstHalf = new byte[(int) length / 2]; secondHalf = new byte[(int) length - firstHalf.length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } if (offset < bytes.length) { throw new IOException("Could not completely read file " + file.getName()); } is.close(); return bytes; } public void splitByteArray(byte[] array) { for (int i = 0; i < array.length; i++) { if (i < firstHalf.length) firstHalf[i] = array[i]; else secondHalf[i - firstHalf.length] = array[i]; } } public void printTwoHalves() { System.out.println("////////FIRST HALF/////////"); for (int i = 0; i < firstHalf.length; i++) { System.out.print((char) firstHalf[i]); } System.out.println(); System.out.println("////////SECOND HALF/////////"); for (int i = 0; i < firstHalf.length; i++) { System.out.print((char) secondHalf[i]); } } public void mergeTwoHalves(byte[] merged) { System.arraycopy(firstHalf, 0, merged, 0, firstHalf.length); System.arraycopy(secondHalf, 0, merged, firstHalf.length, firstHalf.length); System.out.println(); System.out.println("////////MERGED/////////"); for (int i = 0; i < merged.length; i++) { System.out.print((char) merged[i]); } } public static void main(String[] args) { File f = new File("C:/Hello.txt"); FileToByteArray program = new FileToByteArray(f); try { byte[] fileAsByteArray = program.getBytesFromFile(); if (fileAsByteArray == null) return; program.splitByteArray(fileAsByteArray); program.printTwoHalves(); byte[] bytes = new byte[fileAsByteArray.length]; program.mergeTwoHalves(bytes); } catch (IOException e) { e.printStackTrace(); } } }
×
×
  • Create New...