I iterate through a tree structure to collect the paths of the leaf nodes. Which way do you prefer to collect the result of the operation:
a) merge the results of the ... |
I already wrote something that removes the first character of a string and puts it after the remaining substring and then prints it out, the instructions were to reverse the sentence ... |
Here's the method:
public static String CPUcolor ()
{
System.out.println ("What color am I?") ;
String s = getIns() ;
...
|
I am creating a factory that makes rooms, and it is passed an int of steps and a start room and it is supposed to do a step, build a room, ... |
String url = getUrl();
try{
Connection con = getConnection(url, username, pwd);
}catch(ConnectionException e){
cleanUpUrl(url);
url = getUrl();
con = getConnection(url, username, pwd);
}
I've to do something like above. if I don't get ... |
I have a bit of code and need to write a recurrence relation for it. The code simply calculates 2 raised to the nth power.
Any help is appreciated.
public static int ...
|
define recursive method for count(String a,char e).it returns number of e's in the string in 'a'.
|
|
I have the following code which I'm using to get the user to input an integer, check to make sure the input is valid, and if not, ask for input again. ... |
This is from an old test that I'm using to study.
I need to write a recursive method that returns the number of zeroes on the int[] from position 0 and right.
given ... |
Had a question on how to reduce the amount of recursive calls on a self implementation of the pow method. Here is what I wrote, can this be improved?
public static int ...
|
In a school assignment we're supposed to make a soduko-solver. I have a recursive method that's supposed to help me solve the soduko-puzzles. It goes like this:
public void setNumber() {
if (getNext() ...
|
This is a homework question that I am having a bit of trouble with.
Write a recursive method that determines if a String is a hex number.
Write javadocs for your method.
A String ... |
I came across this method browsing the web searching for recursive methods.
Believe me, I cant get its logic. Basically this method finds the amount of ciphers in a given number.
public int ...
|
Is there a way to abruptly return to the method that calls the method below when the condition is met? Something similar to a break for loops.
public void createTree(TreeNode tree) throws ...
|
I am trying to write a recursive method that searches through a list of IData objects and returns a specific implementation. The list contains objects that implements the interface IData.
There are ... |
Just saw this in a past exam paper and am looking for the best way to do it since I can't figure it out. We are not allowed use multiplication in ... |
I just need to find all recursive method in projects. (100+ eclipse java/plugin projects with about ~1 millions lines of code). Since we already found some performance problem caused by some ... |
Hello
Why my reverse method that uses recursion isn't working?
The print statement shows that the operation is done correctly but at the end it seems like only the very ast char of ... |
public static int recursiveReverse(int number, int reversenumber){
if(number <= 0) {
return reversenumber;
}
reversenumber ...
|
I had an exam today and there was a question which I don't really remember the exact code.
But what I do remember that inside the method exampleMethod(int num) there was a ... |
Please only help if you know how the game Boggle works. So I created a random 4x4 2D array of strings. I used strings because Q has to be Qu. Nonetheless ... |
I have a Java application that parses pdf files in a directory and its subdirectories and creates a database using the information found in the files.
Everything was fine when I was ... |
public class StampaInversa {
private static class NumberWithCounterAndAverage{
private int number=0;
private int counter=1;
private int average=0;
public int getNumber(){
...
|
I am trying to practice understanding recursion but the following program has me stumped. How is the answer being returned as 14? Can someone show me how this is calculating? I ... |
I'm writing a Boggle-solver for my class. I have it working perfectly; however, in order to increase the efficiency of the algorithm, I want to write an isValidPrefix method. This method ... |
Thanks for the help, but I'm learning from a book and would like to figure out this recursion method. I know it would be easier to use iterative method or even ... |
hello, Every memo, or document, has words that are a waste of space, i need to store usefull words and their projectNumbers. (the code will explain) I'll include chunks of code to help, but the general idea is to compare each token to every line read from a file; in = new BufferedReader(new FileReader(inputFile)) X = in.readLine()// X is a word ... |
Hi, i have following Problem. On one Panel i have eight JComboBox's named JComboBox(1-8). Now i have following Method to fill the ComboBox model public void updateJComboBox() { DefaultComboBoxModel model = (DefaultComboBoxModel)jComboBox1.getModel(); Rohstoff Ro =null; Object[] tabelle = all_Rohstoff.getAll(); for(int i=0;i< tabelle.length;i++) { Ro = (Rohstoff)tabelle[i]; model.addElement(Ro.getName()); } } This is working fine, but i don't want to repeat the method ... |
hello everyone, I wrote this dummy tree class which is associated to itself, and i populate it using a recursive method. The recursive method, getMyChildren, is used to add child objects to parent object, and then grandchildren to children, and so on. In my method, after the recursion, I test the collection of children and they're always empty, even though they're ... |
Hi all, I need to write a method which sorts my objects. The parent object can have n levels of child data, for example, a Customer can have many Sales, each Sale can have many SalesAttributes, each SalesAttribute can have many TransactionAttribute, etc. etc. I need to display all of the data sorted; I can do a simple sort using Comparator, ... |
I am working on a recursive method that accepts an int and reduces it to a single digit. It is part of my numerology program. I keep getting an error from the compiler when I call the recursive method. I think maybe I am calling it wrong, but I don't know the right way. We didn't go over it in class... ... |
How do determine the recursive formula? I have the following code that I need to rewrite into a recursive method: // iterative method public static int integerDivision(int n1, int n2) { int result = 0; while ( n1 >= n2 ) { result = result + 1; n1 = n1 - n2; } return result; } public static void main (String ... |
hi, i'm writing a recursive method that returns a string containing a binary tree "printed" sideways,with the right subtree above the root node and the left subtree below the root node. Each subtree is indented by three spaces more than its root. for example, the input binary tree is: A / \ B C / \ D E the returned string ... |
What are you passing in? If you make this call with powR(5,3) what will happen? "if (exp == 0)" is false since exp is 3. so, we go into the else. this will return (5 * ) ok, what does powR(5,2) return? it returns (5 * powR(5,1)), which returns (5 * powR(5,0)), which returns 1. so basically, we ... |
Hi all, I want to print the absolute path of all files (including the files in subfolders) in a given directory [C:/Source]. Please help me what is wrong with my code... import java.io.File; public class test { public void getDirectoryList(String Path) { String[] dirContents; File dir = new File(Path); if (dir.isDirectory()) { dirContents = dir.list(); for (int i = 0; i ... |
this is the task that i hopefully did below in my program im supposed to : Write a recursive method that takes two sorted lists in increasing order.The method creates and returns a new list representing the union of the two lists.The resulting list should be sorted. The method should traverse the lists only once. The method should be implemented using ... |
Hi here I am again, I know how recursive method works but the problem I'm facing now is analyzing this recursive method. I'm just testing the method. public static boolean checkGrid( int arrayLength, int grid[][], int x, int y ) { if( arrayLength != 0 ) { //if( x < 4 ) //{ checkGrid( arrayLength - 1, grid, x + 1, ... |
|
I've got a problem with a recursive method that is not saving the data correctly. I'm traversing an XML node list and pulling information and creating an object tree. The below method traverses the XML tree correctly. The problem is that the grandchildren are being lost. So, at the end I'm left with only the root object and one level of ... |
Hi all. I tried to write a recursive method to get the prime factorization of a given number. This is what i have (notice the method uses the isPrime method: import java.util.Scanner; public class RecursivePrimeFactors { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter a number"); int num = input.nextInt(); printPrimeFactors(num); } private static void printPrimeFactors(int num){ if(isPrime(num)){ ... |
|
As a type 1 greenhorn I have come to a grinding halt with the following code. import java.util.Hashtable; import java.util.Enumeration; public class RamConfig { static int[] sizes = {0, 8, 16, 32, 64}; static Hashtable configs = new Hashtable(64); static int slots[] = new int[4]; public static void main (String args[]) { System.out.println("Available DIMM sizes are: "); for (int i=0; i ... |
|
a) What is the output of the following recursive code? public static void main(String[] args){ System.out.println(foo(4)); } public static int foo(int n){ System.out.println(n); if (n == 0) return n; else return n + foo(n - 1); } b) Write a recursive method that accepts a single String as a parameter and returns ther reverse of that String. For example, calling the ... |
|
|
import java.lang.String; import java.io.*; import java.util.*; public class CountVowels{ public static void main(String args[])throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the String:"); String text = bf.readLine(); int count = 0; for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') { count++; } } System.out.println("There ... |
|
I am getting a stack overflow error when I run the driver window for my tic tac toe ai. Java Code: public int comp(String[] board, int[] moves, int x, int index){ if(index==9) return 50; if(humanWin(board)) return 100; if(compWin(board)) return moves[x]; moves=posMoves(board); if(index%2==0) { board[moves[x]]="x"; comp(board, moves, x++, index++); } else { board[moves[x]]="o"; comp(board, moves, x++, index++); } return 100; } The ... |
What do see that is wrong? Can you help me with my else statement? Write a recursive method with method header void printArray(int[] a, int size) that prints the first size elements of array a on separate lines. printArray() should check to make sure size is a positive number less than or equal to the length of array a ... |
Hi, I have a question about a small pathfinding problem. I got a 2D table which symbolize a labyrinth. The table only contains a ' '(white space), a 'B', a 'E' and a 'W' B: begin position E: end position W: wall I need to write out all the pads from B to E. (a) I may not cross a wall ... |
|
import java.util.Scanner; public class Interest { public static void main(String[] args) { Scanner kbd=new Scanner(System.in); double principal=0, percentage=0, result=0, years=0; System.out.println("Enter the principal amound in dollars: "); principal = kbd.nextDouble(); System.out.println("Enter the annual interest rate as a percentage: "); percentage = kbd.nextDouble(); System.out.println("Enter the number of years: "); years = kbd.nextDouble(); System.out.println("The total value after compounding is "+ recursiveInterest(result)); } public ... |
|
thank you, but the code I have provided is what I have so far. I thought it would work, when returning the find(word) method. in the tester class i would write something like System.out.println(s.find(with); I think I will need to work on it a bit more, but thank you so far! best regards |
/** This class is responsible to fetch the address details from Database and send it back in form of * CompanyResponse XML String. It accomplishes this by performing a series of below mentioned steps: * - Parse Request XML and Fetch search parameters. * - Call the Stored Procedure * - Iterate through ResultSet * - Prepare Response XML * */ ... |
The Begin array is used to store the beginning of each convention. It isn't changed. It is used to change n so that if you choose to use the n you don't end up using the convention that ends on the same day as the convention you chose begins. I hope that made sense. |
For recursion to be meaninful in this case you should build the recursion according to the "divide and conquer" principle. Let the i and j parameters represent a number range. In each recursive step you divide this range in half. Then you make two recursive calls, one with the left subrange and one with the right subrange. This continues until i ... |
A recursive algorithm solves a problem by solving a little bit of the problem, leaving a simpler version of the problem left over. Then it solves that remaining problem the same way. For example, the factorial of N is either; 1, if N is 1, or N times the factorial of (N-1) For more detail, read a textbook or Wikipedia or ... |
|
Hi everybody,m a beginner ,while trying to execute the following code in the output i can't getthe symbol ( ' ) correctly printed ,plz lemme know where m i at fault- class Song{ public static void lyrics(int n){ if(n==1){ System.out.println("No bottles of beer on the wall,; no bottles of beer, ya' can?t take one down,ya' can?t pass it around, 'cause there ... |
|
|
Is there a way to break out of a recursive method once a condition is met? For example, I want to exit a recursive method that searches a linked list for a particular number when the first occurence of the number is found even though there may be several occurences of the same number in the linked list. MH |
|
In words can you describe how a recursive solution could solve the problem of determining if B is a multiple A. What you should think about is: 1. What changes on each recursive call? 2. What stops the recursive call from recursively calling itself for ever? 3. After each recursive call, how does the previous recursive call get me closer to ... |
|
|
|
javaistoohardfornoobslikeme wrote: so what i'm trying to ask is, am i somewhere close to having a recurvise method, if not how do i change my code so it is This method is technically recursive, because it calls itself. But far from achieving a recursive tree search, this code shows you have little understanding of its meaning. To search you have to ... |
**** *** ** * * ** *** **** and i needed * ** *** **** **** *** ** * So its only changing the order it prints it. but where would that be changed? i tried swapping the bottom part where the parameter is modified and the print but it does not work |
/*************************************************************** * Recursively computes a shape from a BufferedImage by scanning * horizontal lines and adding non-opaque sections to a preallocated * empty Area. To begin recursion, supply empty/default values: * getShapeFromTransparent( _allocatedBufferedImage, new Area(), * new Point2D.Double(), false, new Point2D.Double() ). * * @param BufferedImage BufferedImage of TYPE_INT_ARGB * @param Area new Area() * @param Point2D new Point2D.Double() * @param ... |
|
|
|
pm_kirkham wrote: @georgemc It's nasty in that you have three functions which operate on parts of a whole object rather than one which operates on the whole. That makes it three times harder to maintain and creates constraints on what a subclass can do - it must override all three. It also means it's harder to ensure consistency if you are ... |
|
After a first replacement I have: @c.descrioption text1 {@c.entity text2 text3 {@c.nested1 text3 {+@c.nested2+ text4 *NESTED3*}}text6} Next I need to process the nested @c.nested2, and it's value is taken from hashtable as well as . A key=c.nested2 value equivalent for returning object is NESTED2 NESTED3 After a second replacement I have: @c.descrioption text1 {@c.entity text2 text3 {@c.nested1 text3 NESTED2 NESTED3}text6} Next ... |
Never, ever catch exceptions silently. If something is broken in your code in those try blocks, you'll never know it. At least put "e.printStackTrace();" in there. It's really, really sick that you're reading a file in your toString method. It's still not clear what your question is. That's because you insist on asking it in terms of tweaks to a buggy ... |
public class csc142review8 extends JFrame implements ActionListener { private JButton button; private FlowLayout layout; private JTextField textField; private String f(String xStr, char n, String rStr, int c, int l) { if (c < l) { return rStr + f(xStr, Character.toUpperCase(xStr.charAt(c)), rStr + n, c+1, l); } else return ""; } // set up GUI and event handling public csc142review8() { super( ... |
|
The reverses twice because it will first add a space, reverse (puting the space on the correct side) take one of the #'s off and then after it prints it will reverse it again so that the blank space will be added to the correct position again. This is my logic anyway. |
Yes, but if it's calling itself then what will happen? You start with 17, that is less than 100 so it calls itself passing the value (17 * 2). So it's called itself now, again, with a value of 34 which is less than 100 so it calls itself (again) passing the value (34 * 2). Once again 68 is less ... |
|
Your iterative method isn't great. At the very least, it's indented poorly. But also you're swapping values sometimes when you really don't need to. Anyway, try expressing the algorithm textually. The recursive approach will probably jump out at you. One thing that might help is to consider that you have two halves to the array you're sorting: the sorted half and ... |
hi, i'm writing a recursive method that prints a binary tree in side ways. (the right child is always a line below the root and the left child is always a line above the root) for example, the input binary tree is: A / \ B C / \ D E the returned string shoud be(note the child nodes have 5 ... |
Do you have a variable called max outside the method ? Because max = current.info or max = current.link.info are doing nothing but setting the method paramter max to the value. If you have a instance variable called max then either refer to it using this.max or rename it to maximum or something similar. |
I need to make a method that prints the original strings followed by a mirrored of that string using recursion, so if I make a call printMirrored("world") I should get worlddlrow I am having a hard time to implement this method, and BTW I am new to Java. Thanks for checking this post and your time. |