• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cant get this program to output

 
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use eclipse
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, you can try control-D instead. Does that work?

Henry
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic