Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2106 > unrolled thread
| Started by | bilsch <bilsch01@gmail.com> |
|---|---|
| First post | 2012-09-25 18:57 -0700 |
| Last post | 2012-09-26 09:45 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.help
problem delimiting a string bilsch <bilsch01@gmail.com> - 2012-09-25 18:57 -0700
Re: problem delimiting a string Knute Johnson <nospam@knutejohnson.com> - 2012-09-25 21:24 -0700
Re: problem delimiting a string Roedy Green <see_website@mindprod.com.invalid> - 2012-09-26 09:45 -0700
| From | bilsch <bilsch01@gmail.com> |
|---|---|
| Date | 2012-09-25 18:57 -0700 |
| Subject | problem delimiting a string |
| Message-ID | <k3tnen$75t$1@dont-email.me> |
The fragment with the delimiting problem is listed below. The objective
is to get Scanner to accept firstname midname and lastname as a single
string using the ENTER key as the string delimiter rather than use the
spaces between first, middle and last as delimiters. The two statements
concerned with delimiting are straight out of a java text book so I
assumed they would work (I don't actually know what they mean). The
compiler complains about the line:
Scanner.useDelimiter(lineSeparator);
It says: cannot make static reference to the non-static method
useDelimiter(String) from the type scanner. Your comments will be
appreciated. TIA. The fragment is as follows:
/* Extracts initials from whole name
File Ch2Monogram.java
*/
import java.util.*;
class Ch2Monogram2a {
public static void main(String[] args){
String partName, firstName, midName, lastName;
Scanner console = new Scanner(System.in);
String lineSeparator = System.getProperty("line.separator");
Scanner.useDelimiter(lineSeparator);
System.out.println("Enter your whole name: first middle last");
}
}
[toc] | [next] | [standalone]
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Date | 2012-09-25 21:24 -0700 |
| Message-ID | <k3u010$d7r$1@dont-email.me> |
| In reply to | #2106 |
On 9/25/2012 6:57 PM, bilsch wrote:
> The fragment with the delimiting problem is listed below. The objective
> is to get Scanner to accept firstname midname and lastname as a single
> string using the ENTER key as the string delimiter rather than use the
> spaces between first, middle and last as delimiters. The two statements
> concerned with delimiting are straight out of a java text book so I
> assumed they would work (I don't actually know what they mean). The
> compiler complains about the line:
>
> Scanner.useDelimiter(lineSeparator);
>
> It says: cannot make static reference to the non-static method
> useDelimiter(String) from the type scanner. Your comments will be
> appreciated. TIA. The fragment is as follows:
>
> /* Extracts initials from whole name
> File Ch2Monogram.java
> */
> import java.util.*;
> class Ch2Monogram2a {
>
> public static void main(String[] args){
>
> String partName, firstName, midName, lastName;
> Scanner console = new Scanner(System.in);
> String lineSeparator = System.getProperty("line.separator");
> Scanner.useDelimiter(lineSeparator);
> System.out.println("Enter your whole name: first middle last");
> }
> }
console is an instance of a Scanner object. If useDelimeter() were a
static method of the class Scanner you could use that line but it is
not. Use console.useDelimeter(lineSeparator) instead.
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-09-26 09:45 -0700 |
| Message-ID | <d8c66810c48t3lu9h7lfbs797dnul8akj6@4ax.com> |
| In reply to | #2106 |
On Tue, 25 Sep 2012 18:57:43 -0700, bilsch <bilsch01@gmail.com> wrote, quoted or indirectly quoted someone who said : >Scanner to accept firstname midname and lastname as a single >string using You don't want a Scanner. You want ordinary BufferedReader.readLine See http://mindprod.com/applet/fileio.html for sample code. -- Roedy Green Canadian Mind Products http://mindprod.com The iPhone 5 is a low end Rolex.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.help
csiph-web