Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 linked list data
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bryce_21




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu May 01, 2014 10:54 am   Post subject: RE:linked list data

Well, have you tried anything?
Raknarg




PostPosted: 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?
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
bryce_21




PostPosted: 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);
}

}
}
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: