> First question;
> i tried using the a code like this and it didn't work, this is an extract:
>
> ...........
> String name;
> double amount;
> System.out.println("Type your name");
> name=(String)System.in.read();
> System.in.read();System.in.read();
> amount=(double)System.in.read();
> System.in.read();System.in.read();
> System.out.println(name);
> System.out.println(amount);
> ......
Your right! First try to use try...catch in each input output to see
if will compile without errors and then run it to see what errors that
there may be. In NetBeans I get six errors right from the start. Add
throws IOException to the main class and it will narrow you down to
one.
name = (String) System.in.read();
I get inconvertible types
found :int
required: java.lang.String
With the code completion in NetBeans you can see that System.in (then
type the period) will
show that read() is an integer.
The cast to String is not working.
If you try
name = System.in.toString();
You get an idea of what the input is doing.
here is a try...catch
System.out.println("Type your name");
try{
name = System.in.toString();
System.out.println(name);
}catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE,
null, ex);
}
I get an object from java.io.bufferedinputstr...@3e25a5
(your @number will be different so don't worry)
So you see we might as well just build a class that uses
BufferedInputStream.
I know that I have before for applets and it works well. That's what
your keyboard is doing.
see: http://www.javadoconline.com/
and type in BufferedInputStream
We can't tell if you used a class for this or tried it in the main
class by itself.
Try to build a class that gets and sets the fields then call it
with new YourClassName();
You are in the right place to learn how to get those lines to work so
Welcome. Just dig in to the lessons and you will find better ways of
doing input and output.
I'm no expert but it was fun trying to help a new programmer. You will
too.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---