Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 JAVA user input
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Darkshining




PostPosted: Mon Jan 23, 2006 7:35 pm   Post subject: JAVA user input

Umm.. Extremely new to JAVA
how can i write a program that ask for input on the temperature of water and see if it's below 0. if it is, then say water is frozen, if not say water is water..
thanks a ton
Sponsor
Sponsor
Sponsor
sponsor
Martin




PostPosted: Mon Jan 23, 2006 7:45 pm   Post subject: (No subject)

http://www.google.com/search?q=java+tutorial&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official
turboliux




PostPosted: Tue Jan 24, 2006 1:21 pm   Post subject: (No subject)

this one takes input from user and gives the square of it
code:
import java.io.*;

class mySquare {
       
        public static void main (String args []) {
                BufferedReader in;
                String text;
                int x = 0;
               
                try {
                        in = new BufferedReader(new InputStreamReader(System.in));
                        text = in.readLine();
                        x = Integer.parseInt(text);     
                }
                catch (Exception e) {
                        System.out.println ("error! Type only numbers!");                     
                }
               
                x = x*x;
                System.out.println(x);
               
        }              
}

btw, if you dont know about "if" statements, then read this example:
code:
String message = "";
boolean statement = true;
boolean statement2 = (4>5);  //obviously, if you know math, it means false
if (statement){
  //do something here like:
  message = "awesome!";
}
else if (statement2){
  message = "its ok!";
}
else {
  message = "useless =(";
}

the string message becomes "its ok!"
turboliux




PostPosted: Thu Jan 26, 2006 11:04 am   Post subject: (No subject)

note: the message becomes "awesome!", not "its ok!" Embarassed Razz
[Gandalf]




PostPosted: Fri Jan 27, 2006 7:18 pm   Post subject: (No subject)

Look up the Scanner class for the best way to do it.

I was in the process of making a tutorial of input using the Scanner class a while ago, but never got around to finishing it... Maybe after exams.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: