11 Replies - 503 Views - Last Post: 06 February 2013 - 07:12 AM Rate Topic: ***-- 1 Votes

#1 nikki7921  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-February 13

Syntax for accepting a character in java without scanner class

Posted 05 February 2013 - 11:59 PM

Syntax for accepting a character in java without the use of scanner class.just the syntax
Is This A Good Question/Topic? 0
  • +

Replies To: Syntax for accepting a character in java without scanner class

#2 Limecore  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 91
  • Joined: 28-November 12

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 12:48 AM

Why do you not want to use the scanner class? It would be much easier to use the scanner class directly, or make a method that also checks the input.
I remember reading there is another way(the scanner class uses this) but I do not know off the top of my head what it was. (It may be I/O streams, or I may just be getting my c++ confused with my java)
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7872
  • View blog
  • Posts: 13,354
  • Joined: 19-March 11

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 12:54 AM

Not sure what you're asking, but it wouldn't be a matter of syntax. You'd have to find the right combination of objects - I'm thinkin BufferedReader, maybe wrapped around some other Reader, ultimately opened on System.in, which is an InputStream.

Go to the Java API reference and start reading on BufferedReader and InputStream and maybe you'll find the right way to do this. You'll probably learn a lot about file IO in the process.
Was This Post Helpful? 1
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 01:00 AM

View PostLimecore, on 06 February 2013 - 01:18 PM, said:

Why do you not want to use the scanner class?


Exactly my point...Java has provided such a nice class called Scanner for all user input operations.

Quote

Why do you want to go against the currents when you can go along with the currents?


regards,
Raghav

This post has been edited by raghav.naganathan: 06 February 2013 - 01:06 AM

Was This Post Helpful? 1
  • +
  • -

#5 nikki7921  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-February 13

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 01:08 AM

View PostLimecore, on 06 February 2013 - 12:48 AM, said:

Why do you not want to use the scanner class? It would be much easier to use the scanner class directly, or make a method that also checks the input.
I remember reading there is another way(the scanner class uses this) but I do not know off the top of my head what it was. (It may be I/O streams, or I may just be getting my c++ confused with my java)

i have to write a program and i am required not to use scanner class
Was This Post Helpful? 0
  • +
  • -

#6 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 01:11 AM

Ok...then

BufferedReader bufferredreaderObject = new BufferedReader(new InputStreamReader(System.in));


will be the best bet...

Well, you need to import package
java.io.*


regards,
Raghav

This post has been edited by raghav.naganathan: 06 February 2013 - 01:15 AM

Was This Post Helpful? 2
  • +
  • -

#7 nikki7921  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-February 13

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 01:13 AM

thats all you need?
Was This Post Helpful? 0
  • +
  • -

#8 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 01:16 AM

Not really, you need to use the object of BufferedReader to use a readLine() method and read a character.

regards,
Raghav
Was This Post Helpful? 2
  • +
  • -

#9 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7872
  • View blog
  • Posts: 13,354
  • Joined: 19-March 11

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 01:16 AM

Try it and see - presumably that's the point of the assignment, is to figure this stuff out. So get figuring.
Was This Post Helpful? 1
  • +
  • -

#10 nikki7921  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-February 13

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 01:16 AM

thank u :)
Was This Post Helpful? 0
  • +
  • -

#11 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1406
  • View blog
  • Posts: 3,121
  • Joined: 05-April 11

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 07:01 AM

			InputStreamReader reader = new InputStreamReader(System.in);
			char character = (char) reader.read();


That's the easiest way to read a single character :) Be careful with the whitespaces being entered though
Was This Post Helpful? 2
  • +
  • -

#12 nikki7921  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-February 13

Re: Syntax for accepting a character in java without scanner class

Posted 06 February 2013 - 07:12 AM

Thank you!!! Thank you!! that was just what i needed!!! thank U :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1