Results 21 to 29 of 29
Thread: newbie guidance.
- 10-17-2010, 08:23 PM #21
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
- 10-17-2010, 09:07 PM #22
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
Parsing with scanner on strings..
Obviously the default delimiter is the white spaces, is there a delimiter that would break the string into individual characters?
- 10-17-2010, 09:16 PM #23
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
You can use the charAt() method for that, after you read in the entire String.
Ever seen a dog chase its tail? Now that's an infinite loop.
- 10-17-2010, 09:22 PM #24
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
ok maybe better if i show you.. im trying to recieve a string and print each char on next line heres what i have so far , maybe you could write it up in puesucode and i'll try compile it
Java Code:import java.util.Scanner; public class ap { public static void main(String[]args) { String n; Scanner jennifer = new Scanner(System.in); System.out.println("Please enter a String"); //jennifer.useDelimiter(""); while (jennifer.hasNext()) { n = jennifer.next(); System.out.println(n); } } }
- 10-17-2010, 09:28 PM #25
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Maybe it would be best if you write down the output you're trying to get, to avoid any confusion. What I'm getting from you, is that you want the user to input a string, and then print out every individual character in a new line. If that's the case, the pseudocode would be:
If that's what you're trying to achieve, you don't need to use a scanner more than once.Java Code:prompt user for input store input in String variable for every index from 0 to strings length - 1 print out character at current index using charAt() new line end loop
Ever seen a dog chase its tail? Now that's an infinite loop.
- 10-17-2010, 09:46 PM #26
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
ok im reading string class api right now , getting past 3rd line of your code.
- 10-17-2010, 10:20 PM #27
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
I cannot get that for loop...ughhh
- 10-17-2010, 10:25 PM #28
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Can you write a small snippet that has an array of 5 ints and use a for loop to print each array element in a separate line? Strings can be seen as arrays of chars, so the method of iterating through it is pretty much the same.
Ever seen a dog chase its tail? Now that's an infinite loop.
- 10-17-2010, 10:31 PM #29
Senior Member
- Join Date
- Oct 2010
- Location
- Newark,nj
- Posts
- 111
- Rep Power
- 0
Similar Threads
-
Guidance for SCJP
By sairam in forum New To JavaReplies: 1Last Post: 06-30-2010, 09:21 AM -
Guidance needed
By Curtiz in forum AWT / SwingReplies: 1Last Post: 03-23-2010, 05:41 PM -
need guidance in component placement
By rdtindsm in forum AWT / SwingReplies: 2Last Post: 05-10-2009, 04:14 PM -
Guidance in writing a compiler
By Jeremy in forum Advanced JavaReplies: 2Last Post: 11-28-2008, 11:25 PM -
Guidance
By gizdev in forum New To JavaReplies: 5Last Post: 09-07-2008, 07:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks