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:
Java Code:
```import java.io.*;
public class MathGame{
public static void main(String args[]) {
int num1, num2;

try {
System.out.print("\nFirst Number: ");
System.out.print("Second Number: ");
}
//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));
}
}```
and in the console looks like this:

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
Java Code:
` System.out.println(num1 + "*" + num2 + "/" + "(" + num1 + " + " + num2 + ")" + "-" + num1 + " = " + ((num1 * num2 / (num1 + num2)) - num1));`
and as far as I know it works well (any tip will be cool)

then I get stuk in the float stuff, searching by internet found this code, so I added:
Java Code:
```float myFloat;
so the final code looks like this:
Java Code:
```import java.io.*;
public class MathGame{
public static void main(String args[]) {
int num1, num2;

//my own:

float myFloat;

try {
System.out.print("\nFirst Number: ");
System.out.print("Second Number: ");
}
//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));

}

}```
then the console give me errors like:
(the parts in red are the leetter that the console shows me)

MathGame.java:19:cannot find simbol
symbol: variable myInputStream

Then I erase the part "my" for pure intuition (see what the hell happens) and appears:

MathGame.java:19:cannot find simbol

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!!!

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....

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!!!

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

5. ## Re: About Float and readLine() begginer problem.

i don't understand (i don't know about java actually), why you use:
Java Code:
`myFloat = Float.parseFloat(myInputStream.readLine());`
where you declare "myInputStream" variable? and you said, you changed it to be like this?

Java Code:
`myFloat = Float.parseFloat(InputStream.readLine());`
(the same question as the above...)

wasn't it should be:
Java Code:
`myFloat = Float.parseFloat(reader.readLine());`
right? because "reader" is your input stream...

CMIIW
Last edited by chipp; 02-17-2012 at 07:15 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:
Java Code:
```import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
public class MathGame{
public static void main(String args[]) {
int num1, num2;
//my own:

float myFloat;

try {
System.out.print("\nFirst Number: ");
System.out.print("Second Number: ");
}
//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));

}

}```
Thank you, by the way...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•