Implementing Fast Fourier Transformation Using Recursion
May 5, 2015
I'm trying to implement fast fourier transformation using recursion, at line 28 I'm getting null pointer exception.The algorithm is suppose to break the array in two parts computes real' and imaginary' at the end to each call stores the value in each call. After which further divide the array in two parts and compute.
I have a problem that is associated with Fast Fourier Transform of an image. I've made an application with some filters for an images. It's a program with JLabels for displaying images before and after filtration and JButtons for filters. So, my problem is with FFT for an image, i've seen examples for that transformation, but i really don't know how to use that in my program.
I upload xml files in my hsp page, then in the post method of my servlet i try to make a transformation on those files and display the data on a html page.
Here is the source of my post method. What's wrong with this source and how i can display the data contains on those xml files?
Java Code:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String xmlFile = request.getParameter("fichier"); Source xmlInput = new StreamSource(new File(xmlFile)); Source xsl = new StreamSource(new File("fichxsl.xsl"));
[Code] .....
My code doesn't work, what's wrong with it ? if there's another way to make display the uploaded xml file's data on a html or jsp page.
As part of a homework assignment in my 1st Java Class, I am creating my own Circular Generic LinkedList and Array class. My class uses the Queue Interface Extends Iterable but I am creating my own methods to work with. For the most part, I believe I have been successful in creating the class aside from one method. That method is the Iterator<E> iterator().
/** * Return a fail-fast iterator, which throw a java.util.ConcurrentModificationException * if the client modifies the collection (via enqueue(...) or dequeue()) during iteration. */ @Override public Iterator<E> iterator() {
I don't understand how an iterator, let alone a "fail-fast" iterator ties into my project. I've spent hours reading up on a way to imploy my own generic fail-fast iterator but to no avail.
I feel like I could come up with some workable code if I knew what the point is to useing a user-defined, non Java Library iterator is to do.
As well, does throwing a ConcurrentModificationException require a try and catch block?
I'm currently working on a RSA Encryption using Fast Exponential technique. As the numbers I'm working with will be very huge, I am forced to use BigInteger.
As this is the first time I'm using Big Integer, I encountered quite a number of issues. I'll try my best to explain the errors I'm facing:
1. I had done this step: BigInteger d;
So I'm currently trying to get d = 0;
However, I keep getting an error required: BigInteger, found int.
When I changed it to d = new BigInteger(0) , I get this error:
java:19: error: constructor BigInteger in class BigInteger cannot be applied to given types;
d = new BigInteger(0); ^ required: no arguments found: int reason: actual and formal argument lists differ in length
Part of Code:
public class BigFastExponential { BigInteger e; // public exponenet: all has this BigInteger d; // private key: only key owner has this BigInteger n; // public modulus: all has this
/** * Create a LongRSA object for a public key holder, with just e and n. */ public BigFastExponential(BigInteger public_e, BigInteger public_n)
I am trying to make a game, for some reason i have begun to get a java.lang.StackOverflowError.
I am not exactly sure how i can fix it. only removing line 14 from infopannel1 (and everything that used that class.) seems to work. im not sure what else i can do to fix it. or why its resulting in stack overflow for that matter.
I am putting in a link for the files i wrote this using bluej (several classes have no relevance, errorv2, demonstration, folderreadertest, ReadWithScanner, saveloadtest, menutest,rannum, and menutestTester. are all irrelivent to my problem.)
How to add the sum of an array with a recursion, but I don't understand how to use recursion. I just understand that it calls back the method. I am nearly done with the code.
import java.util.Scanner; class Question1{ public static void main(String[]args){ Scanner s = new Scanner(System.in); int size, sum; System.out.println("Please input how many numbers will be used"); size=s.nextInt();
public void myFunc(MyNode n, ArrayList<MyNode> path) { boolean hasChildren = false; path.add(n); int index = path.indexOf(n); ArrayList<MyNode> statefulPath = new ArrayList<MyNode>();
[Code] ....
I have similar code that I stepped through in a debugger. After running the code I found that it built the desired tree, in this case a root node H with left child L and right child P. I want list of lists to contain all paths from root to leaf. I expected [H, L] and [H, P]. I discovered that statefulPath is not stateful; after a recursive stack frame pops, statefulPath still contains n! But that stack frame just popped! I expected to see statefulPath be [H] in the debugger and it was [H, L]! So I later have a list [H,L,P] which I don't want. How do I make the statefulPath list I want for my algorithm?
I have a question related to the code below, that I do not understand. The aim is to count all files and subdirectories in an ArrayList full of files and subdirectories. So I have to count every file and every subdirectory.
The code concerning counting files is clear to me - every time d is of the type file I have to increment n by one. However I thought that I have to do the same thing in case d is a directory, so I would have written the same code for directories.
So what does "n += ((Directory) d).countAllFiles();" mean? In my understanding the method countAllFiles() is applied again on the object Directory ( as Directory is the class that contains this method), but how is n incremented by this? I thought n should be incremented by one as we did with files.
public int countAllFiles() { int n = 0; for(SystemFile d : content) { if(d instanceof File) { n++;
How the recursion works. I tried to figure out writing down low, mid, high at each recursive call. But I seem to be making a mistake somehow. I don't understand where the values are returned to in
I just started studying recursion and I wanted to know how to create a palindrome number going up from 1 to n then back to 1 like this: "12345...n...54321".
I've done one going downwards and then upwards like this: "n...4321234...n".
Here's my code:
Java Code: import java.util.*; public class PalindromeTest { public static void downPalindrome(int n)
The program I'm working on is supposed to read input from a file and using recursion, print the pattern of asterisks for each value until the value is either < 0 or > 25.For example, if the value was 4, the pattern would look like this
* * * * * * * * * * * * * * * *
The values are stored in a file entitled prog3.dat which looks like this
4 3 15 26 0
I've never used recursion before and haven't been able to find anything showing how it would work with this particular type of problem.Here is what I've been able to come up with so far, but I'm having problems still which I will show following the code.
import java.util.Scanner; import java.io.*; public class Program3 { public static void main(String[] args) throws Exception { int num = 0; java.io.File file = new java.io.File("../instr/prog3.dat"); Scanner fin = new Scanner(file);
[code]...
It appears to be reading the file correctly, but is only printing the top half of the pattern. Also, like I said, I'm not very familiar with recursion, so am not sure if this is actually recursion?
The program I'm working on is supposed to read input from a file and using recursion, print the pattern of asterisks for each value until the value is either < 0 or > 25. For example, if the value was 4, the pattern would look like this
* * * * * * * * * * * * * * * *
The values are stored in a file entitled prog3.dat which looks like this
4 3 15 26 0
I've never used recursion before and haven't been able to find anything showing how it would work with this particular type of problem. Here is what I've been able to come up with so far, but I'm having problems still which I will show following the code.
import java.util.Scanner; import java.io.*; public class Program3 { public static void main(String[] args) throws Exception { int num = 0; java.io.File file = new java.io.File("../instr/prog3.dat"); Scanner fin = new Scanner(file);
[Code] ....
Output:
Please enter an integer * * * * * * * * * * Please enter an integer * * * * * * Please enter an integer
As you can see, I don't know how to make it print the pattern like in the example and am honestly not even sure if this is recursion since I've never actually worked with recursion before.
I was asked to create a word pyramid program using recursion. I understand the concept of recursion (i.e. a method calling itself with the problem it is solving getting simpler and simpler each time) but I am having issues writing the program. Here is my code:
public static void main(String[] args) { //This program will create a word pyramid by using a recursive algorithm. //For example, the output of "DOGGY" should be: //DOGGY //OGG //G //This program will also use a recursive algorithm to accomplish this. String userWord = JOptionPane.showInputDialog(null, "Hello and welcome to the Word Pyramid program."
We are supposed to create a MergeSort method without the using recursion. Most of the code is already completed, the only thing that I believe I need are two for loops (an inner and an outter) that will make calls to the merge method. I need implementing the sort method of the merge sort algorithm without recursion, where the length of the array is a power of 2. Keep merging adjacent regions whose size is a power of 2. For ex: lengths will be 1, 2, 4, 8, 16,.
public class MergeSorter { public static void sort(int[] a) { //for(int i = 1; i <= a.length; i++) the parameters for the for loop are wrong. { merge(0,0,1,a); merge(1,1,2,a); merge(2,2,3,a);
/** * This class encapsulates a simple dice game. The number of dice and number of sides on those dice are given by instance variables. The outcomes ArrayList holds a list of all possible outcomes of throwing that number of dice with that number of sides. * * If there were 2 dice, each with 6 sides, then possible outcomes would include 1 1, 1 2, 1 3, 1 4, 1 5, 1 6, 2 1, 2 2, 2 3, and so on. * * Your task is to complete the methods that calculate the possible outcomes. One method calculates outcomes allowing for repeated numbers. One method calculates the outcomes of a fictional dice game where repeated numbers cannot occur. * * You must use recursion. This is a variation on the permutations problem from the book. */
public class Dice { private static int numberOfSides; private static int numberOfDice; public ArrayList<String> outcomes;
[code]...
I manage to calculate the numberOfOutcomes correctly, but then get a nullPointerException. Also, is there a way that I can use getNumberOf Outcomes without making it static? The testing code that the teacher provided is using it in another class and if I make it static, then it doesn't work in that file.
how the code is getting all the permutations of a string with recursion. The following code works correctly but I am having trouble grasping what it is doing.
public class Main { private static void permutation(String prefix, String str){ int n = str.length(); if (n == 0) System.out.println(prefix); else { for (int i = 0; i < n; i++) permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1)); } } public static void main(String[] args) { permutation("", "ABCD"); } }
I see that each character is being appended to prefix through each iteration. So I know it adds "A" then "B" etc etc. I can follow it up until the "D" is appended to the prefix string. After that I don't understand how the D moves back to the str string and then the C moves back to str followed by the D moving back to the prefix string. I have stepped through the code many times in my debugger but still don't see how it moves back to str and knows to send D to prefix and not to send C. I feel I don't understand how recursion behaves therefore I can't follow.
We have Starting point that is (3,0) and an ending point is (1,3). We can only move up and right to get to the ending point by using recursion. We have to list all possible paths from (3,0) to (1,3)
We have Starting point that is (3,0) and an ending point is (1,3). We can only move up and right to get to the ending point by using recursion. We have to list all possible paths from (3,0) to (1,3)
I was able to get from (3,0) to (1,3) but how to list the other paths. This is my code so far
public class Program7 { public static void main(String[] args){ int size = 5; int x1 = 3; int y1 = 0; int x2 = 1; int y2 = 3; System.out.println(x1+" "+y1); System.out.println(x2+" "+y2);
From robosoul's response at StackOverflow, I simply inserted a condition for negative integers (line 12). True enough, the code worked and I was able to trace (pen and paper method) how it is converting the 0 and positive integers to words.
However, I am a bit lost on how it is doing the conversion for negative integers. How it is successfully converting the negative?
I have to alter my Sentence class to find the index of the substring "sip" in Mississippi but I'm really not sure where to begin. This is what I have...
Sentence.java public class Sentence { private boolean outcome; private String sentence; public Sentence(String aSentence) { sentence = aSentence;
[Code] ....
I know that I need to change public boolean find(String t) to public int indexOf(String t) but I'm not sure what to start doing to get the index of "sip".
Recursion in a MineSweeper game. So far, when a user clicks on a square and it has a bomb on it, I reveal the bomb to the user - see clicked(). I also have the ability to show the user if the squares surrounding them have any adjacent bombs - see countAdjacentSquares().
However, I am having trouble with my fillZeros() recursive method. When a user clicks on a square that has zero bombs in its surrounding squares, it not only reveals that square, but also any adjacent squares (horizontally, vertically or diagonally adjacent) that also have zero bombs in its surrounding squares.
I don't have any recursion, if I click on a square with no bombs all it does it set the square to 0, but doesn't continue to check for other empty squares.
Java Code:
import javax.swing.*; import java.awt.*; import java.util.*; public class Square extends GameSquare { private boolean revealed = false; private boolean squareHasBomb = false; public static final int MINE_PROBABILITY = 10; public int mineCount = 0;
/** * Use selection sort to sort the tracks by name. Return a new, sorted ArrayList of tracks. * * @return an ArrayList containing the tracks sorted by name, or null if no tracks exist */ public ArrayList<Track> getTracksSortedByName() { // YOUR CODE HERE if(tracks == null) return tracks;
[Code] ....
Here are my 2 issues (there are 2 lines with compiler errors): I feel like I understand selection sort and binary search, but am not sure how to apply it to the more abstract idea of a Track ArrayList (hence the 2 compiler errors). What should I use to make it work. Lastly, I'm very uncomfortable with recursion, so my guess is there is also probably some logical issue with it in the getTracksSortedByName method.