Results 1 to 6 of 6
- 02-17-2012, 08:49 AM #1
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 5
- Rep Power
- 0
About Float and readLine() begginer problem.
Hi!
ATTENTION!!!: My first post on this forum
Note: I'm spanish, so, forgive me about my pathetic english fails like gramar and lack of bocabulary, and oaf course, terrifying hortographic fails (I'm shure that just now I have more than 10) for more information: I travel to Norway and I learn to SPEACK english, not to writte it XD.
Well!!, first of all, just to say that I try to search a solution to my "wandering" in this forum, but I still dont found it yet, I gess its because shoud be extreemly easy, but still imposible for me (I start this week with the book "Java programming for the absolute begginer" and its the first time in my life I put serious abaut to learn something of programming.
Ok after this small introduction of myself that I know noone cares a damn about it here it goes my cuestioning.
- as a part of the course I start one app to learn about mathematic posibilities in java, the program its called MathGame, withc the code look like this (working and with any problem:
and in the console looks like this:Java Code:import java.io.*; public class MathGame{ public static void main(String args[]) { int num1, num2; BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("\nFirst Number: "); num1 = Integer.parseInt(reader.readLine( )); System.out.print("Second Number: "); num2 = Integer.parseInt(reader.readLine( )); reader.close( ); } //simple exception Handling catch (IOException ioe) { System.out.print("some shit happens.... try again"); num1 = num2 = 1; } catch (NumberFormatException nfe) { System.out.print("Number format incorrect, put a fucking number you assholle!"); num1 = num2 = 1; } //avoid this pitfal, ej: 1+1=11: //System.out.print(num1 + " + " + num2 + " = " + num1 + num2); System.out.println(num1 + " + " + num2 + " = " + (num1 + num2)); System.out.println(num1 + " - " + num2 + " = " + (num1 - num2)); System.out.println(num1 + " * " + num2 + " = " + (num1 * num2)); System.out.println(num1 + " / " + num2 + " = " + (num1 / num2)); System.out.println(num1 + " % " + num2 + " = " + (num1 % num2)); } }

well that's nice , ok. But I wanna make 2 modifications (for my own learning pride)
1: Add decimals! so I tryed to ad Float to the code
2: make a last ecuation line with all mathematic thing I learn (like multiplication, division, parenthesis...)
then:
i add to the code the last line
and as far as I know it works well (any tip will be cool)Java Code:System.out.println(num1 + "*" + num2 + "/" + "(" + num1 + " + " + num2 + ")" + "-" + num1 + " = " + ((num1 * num2 / (num1 + num2)) - num1));
then I get stuk in the float stuff, searching by internet found this code, so I added:
so the final code looks like this:Java Code:float myFloat; myFloat = Float.parseFloat(myInputStream.readLine());
then the console give me errors like:Java Code:import java.io.*; public class MathGame{ public static void main(String args[]) { int num1, num2; BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in)); //my own: float myFloat; myFloat = Float.parseFloat(myInputStream.readLine()); try { System.out.print("\nFirst Number: "); num1 = Integer.parseInt(reader.readLine( )); System.out.print("Second Number: "); num2 = Integer.parseInt(reader.readLine( )); reader.close( ); } //simple exception Handling catch (IOException ioe) { System.out.print("some shit happens.... try again"); num1 = num2 = 1; } catch (NumberFormatException nfe) { System.out.print("Number format incorrect, put a fucking number you assholle!"); num1 = num2 = 1; } //avoid this pitfal, ej: 1+1=11: //System.out.print(num1 + " + " + num2 + " = " + num1 + num2); System.out.println(num1 + " + " + num2 + " = " + (num1 + num2)); System.out.println(num1 + " - " + num2 + " = " + (num1 - num2)); System.out.println(num1 + " * " + num2 + " = " + (num1 * num2)); System.out.println(num1 + " / " + num2 + " = " + (num1 / num2)); System.out.println(num1 + " % " + num2 + " = " + (num1 % num2)); //my own: System.out.println(num1 + "*" + num2 + "/" + "(" + num1 + " + " + num2 + ")" + "-" + num1 + " = " + ((num1 * num2 / (num1 + num2)) - num1)); } }
(the parts in red are the leetter that the console shows me)
MathGame.java:19:cannot find simbol
symbol: variable myInputStream
myFloat = Float.parseFloat(myInputStream.readLine());
Then I erase the part "my" for pure intuition (see what the hell happens) and appears:
MathGame.java:19:cannot find simbol
symbol:method readLine()
myFloat = Float.parseFloat(InputStream.readLine());
Well, question is: how I put decimals in this tiny and useless aplication? amI in the right direction? or: were is the fucking problem!!!!!
XD
well, solution +explanation could be extreemly cool,
tusen takk!!!
- 02-17-2012, 08:51 AM #2
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 5
- Rep Power
- 0
Re: About Float and readLine() begginer problem.
May be to much explanation for so stupid problem....
- 02-17-2012, 08:57 AM #3
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 5
- Rep Power
- 0
Re: About Float and readLine() begginer problem.
oooooh! and if my hero can aslo explain me how to change the avatar will be even cooler!!!
- 02-17-2012, 03:53 PM #4
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 5
- Rep Power
- 0
Re: About Float and readLine() begginer problem.
i see how to change the avatar now, thanksXD
- 02-17-2012, 06:11 PM #5
Re: About Float and readLine() begginer problem.
i don't understand (i don't know about java actually), why you use:
where you declare "myInputStream" variable? and you said, you changed it to be like this?Java Code:myFloat = Float.parseFloat(myInputStream.readLine());
(the same question as the above...)Java Code:myFloat = Float.parseFloat(InputStream.readLine());
wasn't it should be:
right? because "reader" is your input stream...Java Code:myFloat = Float.parseFloat(reader.readLine());
CMIIWLast edited by chipp; 02-17-2012 at 06:15 PM.
- 02-19-2012, 12:17 PM #6
Member
- Join Date
- Feb 2012
- Location
- Norway
- Posts
- 5
- Rep Power
- 0
Re: About Float and readLine() begginer problem.
jajajjaa now I see ok that was preety stupid mistake XD ffff...
ok I changed and when compiling apears me this error:

I gess I sould put some values in the parenthesis?
here the new code:
Thank you, by the way...Java Code:import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class MathGame{ public static void main(String args[]) { int num1, num2; BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in)); //my own: float myFloat; myFloat = Float.parseFloat(reader.readLine()); try { System.out.print("\nFirst Number: "); num1 = Integer.parseInt(reader.readLine( )); System.out.print("Second Number: "); num2 = Integer.parseInt(reader.readLine( )); reader.close( ); } //simple exception Handling catch (IOException ioe) { System.out.print("some shit happens.... try again"); num1 = num2 = 1; } catch (NumberFormatException nfe) { System.out.print("Number format incorrect, put a fucking number you assholle!"); num1 = num2 = 1; } //avoid this pitfal, ej: 1+1=11: //System.out.print(num1 + " + " + num2 + " = " + num1 + num2); System.out.println(num1 + " + " + num2 + " = " + (num1 + num2)); System.out.println(num1 + " - " + num2 + " = " + (num1 - num2)); System.out.println(num1 + " * " + num2 + " = " + (num1 * num2)); System.out.println(num1 + " / " + num2 + " = " + (num1 / num2)); System.out.println(num1 + " % " + num2 + " = " + (num1 % num2)); //my own: System.out.println(num1 + "*" + num2 + "/" + "(" + num1 + " + " + num2 + ")" + "-" + num1 + " = " + ((num1 * num2 / (num1 + num2)) - num1)); } }
Similar Threads
-
begginer needs help..?
By lina in forum New To JavaReplies: 4Last Post: 01-15-2010, 04:48 PM -
Receiving Text over a Socket (ReadLine() problem)
By HermanHope in forum New To JavaReplies: 1Last Post: 04-09-2009, 10:35 PM -
Begginer and project
By Gym in forum New To JavaReplies: 6Last Post: 03-24-2009, 01:30 AM -
Hi there, and i have little problem with readLine
By Chesh in forum New To JavaReplies: 10Last Post: 01-17-2009, 08:30 PM -
problem with console.readLine()
By thatguy in forum New To JavaReplies: 1Last Post: 12-14-2008, 07:40 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks