September 04, 2010, 01:56:42 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Console I/O  (Read 695 times)
0 Members and 1 Guest are viewing this topic.
jurka
Moderator
Member
*
*

Reputation: 5
Offline Offline
Posts: 188
Referrals: 0

Awards
« on: August 11, 2009, 03:35:05 PM »

I haven't post here any examples of I/O. Input and output don't just consist of file, printer or database, the simplest variant of this would be printing something in console and also reading from there.

First would be println it's almost same as in java System.out.println just less verbose. All these methods are from object(it's similar to singleton pattern use). Here you can find full list of other methods http://scala-tools.org/sc...brary/2.7.1/scala/Console$object.html.

Ok it's object then Ill have to call out println like this Console.println() ? Actually you can use this way, but there's wrapper called PreDef which allows us to use syntax without the Console.

Real example of Output
Code
GeSHi (java):
  1. println("Hello from println")
Created by GeSHI 1.0.7.20

The example of Input with readLine method
Code
GeSHi (java):
  1. val name = Console.readLine("Name: ")
  2. println("Hello " + (if (name == "Jurka") " do some scala" else " wanna java") + " ? ")
Created by GeSHI 1.0.7.20

Get the value from user, store it and make some if statement usage. Also if you want to be more precise about the data types of what you want user then you could also use readInt, readBoolean, readFloat etc.


// Edit i dont know why these Geshi syntax highlighting boxes look so big :(
Logged
Javaforums.net :: a community about Java software development.
« on: August 11, 2009, 03:35:05 PM »

Your Ad Here
 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.148 seconds with 35 queries.

Google visited last this page September 01, 2010, 09:32:55 PM