Hi,
first of all, if you need read line from input you much rather do
BufferedReader reader = new BufferedReader(new InputStreamReader
(System.in));
and then do
String name = reader.readLine();
(although with this approach you need to add try/catch for
IOException, which you might not be familiar with..)
also you cannot just cast String into double, to parse String to
double you use Double.parseDouble() (for any other number type replace
Double with other type)..
so I would rewrite your code like this:
try {
BufferedReader reader = new BufferedReader(new InputStreamReader
(System.in));
String name = reader.readLine();
String tmp = reader.readLine();
double amount = Double.parseDouble(tmp);
System.out.println(name);
System.out.println(amount);
} catch (IOException ex){
ex.printStackTrace();
}
On Aug 17, 10:15 pm, elvis sarfo <[email protected]> wrote:
> Hi folks, i am a novice to the java programming language and so i would
> definitely worry u guys with a lot of annoying questions but i trust u guys
> will help me out. Thank you very much.
>
> 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);
> ......
>
> Thank u very much hoping to be assisted.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---