• Post Reply Bookmark Topic Watch Topic
  • New Topic

cant get this program to output  RSS feed

 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


****NOTE: To signal end-of-input to your program, type Ctrl-Z in Eclipse or Ctrl-Z
and Enter in a cmd window.*****

Example Runs. (Input is underlined bold.)

In Xanadu did did Kubla Khan
A stately pleasure pleasure dome decree

should return 2

one one
two two
three four
five five
six seven

should return 3

how do i go about entering the ctrl-z to get the output? this is the first program i do that issues NO prompt.
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use eclipse
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alvaroo Hernandez wrote:
how do i go about entering the ctrl-z to get the output? this is the first program i do that issues NO prompt.


Please explain what you mean by this. Do you mean that you can't get ctrl-z to work? Or do you mean that you don't know how to type ctrl-z?

Henry
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so when i type in the example runs i cant get the ctrl-z to work so it can stop and output what its suppose to output.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, you can try control-D instead. Does that work?

Henry
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it work from your command line?  That would let you know if it's a problem with your code or with your tool...
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:Alternatively, you can try control-D instead. Does that work?

Henry

ok so on eclipse i press run and then i input the example run then i put the control-D or ctrl-z and it still doesn't stop running. Its just confusing since this program issues no prompt because if it did i can do that but were supposed to do it without an issue prompt. 
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:Does it work from your command line?  That would let you know if it's a problem with your code or with your tool...

i just now tried it on the command line and it did work there any idea on how to make it work on eclipse?
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There seems something wrong with a program which requires ctrl‑D or ctrl‑Z. You have written an infinite loop and can only exit the loop by closing System.in. You shou‍ld think of some way of passing a sentinel value which allows you to terminate the loop instead.
 
Alvaroo Hernandez
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:There seems something wrong with a program which requires ctrl‑D or ctrl‑Z. You have written an infinite loop and can only exit the loop by closing System.in. You shou‍ld think of some way of passing a sentinel value which allows you to terminate the loop instead.

1. Issues NO prompt.
2. Reads pairs of words until there are no more to be read. You may assume that
the input always contains an even number of words.
3. Prints the number of pairs read where both words are the same. Print only
the number, without any accompanying verbiage, followed by a newline.
**** NOTE: To signal end-of-input to your program, type Ctrl-Z in Eclipse or Ctrl-Z
and Enter in a cmd window.****

these were the instructions. Its much easier if i had prompt the input of 2 strings then compare them but the assignment
says without prompting anything. i got it to work on the cmd window but i don't know how to make it work on eclipse.
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alvaroo,Do as below
open-windows/preferences/general/keys in eclipse,then check for "EOF" in the command section.
now in front of binding option check for the key-"ctrl-z" is binded to EOF,if not then do the changes by pressing ctrl-z in it.it would work then.
i am attaching the snap-it would make your work easy.

Hope this will help you!

Kind Regards,
Praveen.
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of things to note: I don't think in.hasNext() will ever return false when it is opened to System.in.  Also, never close a scanner opened to System.in, even it Eclipse complains about it.

Right now, your program doesn't understand a "line", just words.  So you could type:

    one two
    two three

and (if you could terminate correctly) you would get a count of 1.  Is this what you want?  If so, consider having a value, such as "end", that signals that the loop should be terminated.  Of course, this means you can't type:

    The end is near

so maybe a better way is to look at lines, not words.
 
Dave Tolls
Ranch Foreman
Posts: 3058
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I can see the instructions require the code to treat Ctrl-Z as the end of text, not any other value.
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alvaroo Hernandez wrote:. . .
**** NOTE: To signal end-of-input to your program, type Ctrl-Z in Eclipse or Ctrl-Z and Enter in a cmd window.****
. . .
Unfortunately, you will have to comply with that instruction, even though it is incorrect practice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!