Author |
Message |
bryce_21
|
Posted: Thu May 01, 2014 10:32 am Post subject: linked list data |
|
|
Objectives:
(1) demonstrate the ability to write, compile, and run a simple Java program.
(2) solve a simple problem using recursion.
(3) demonstrate the ability to use recursion.
(4) demonstrate the ability to diagram a Java program.
Instructions:
A. Set up the compiler on your workstation.
B. Write, compile, and run a Java program that:
(1) prompts the user to type a 5 characters such as a 5 digit number,
(2) calls a parameterless. void, recursive function named "reverse" to print the
number backwards.
C. Diagram (i.e. illustrate with a picture) your program completely.
D. e-mail your source code to me.
need help coming up with an algorithm for this project |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu May 01, 2014 10:54 am Post subject: RE:linked list data |
|
|
Well, have you tried anything? |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Thu May 01, 2014 1:52 pm Post subject: RE:linked list data |
|
|
Also, out of curiosity what does the title have to do with the question? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu May 01, 2014 3:11 pm Post subject: Re: linked list data |
|
|
I would guess that has to do with someone's idea of storing a string as a linked list of characters ![Laughing Laughing](http://compsci.ca/v3/images/smiles/icon_lol.gif) |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
bryce_21
|
Posted: Wed May 07, 2014 8:29 pm Post subject: Re: linked list data |
|
|
here what came up when i try storing strings of characters in linked lists
import java.util.Scanner;
public class Reversetest
{
public static String inputstr;
public static int n = 5;
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
inputstr = keyboard.nextLine();
reverse();
}
public static void reverse()
{
if (n >= 0)
{
System.out.println(inputstr.charAt(n-1));
n--;
reverse();
}
else
{
System.exit(0);
}
}
} |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu May 08, 2014 1:04 pm Post subject: RE:linked list data |
|
|
code: |
System.out.println(inputstr.charAt(n-1));
|
Since you are indexing into the string anyway, this is effectively a for-loop. Figuring out how to use e.g.
code: |
System.out.println(inputstr.charAt(0));
|
should give you a better feel for recursion. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|