Results 1 to 6 of 6
  1. #1
    Kaahrl is offline Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    5
    Rep Power
    0

    Default 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;
        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));
          }
      }
    and in the console looks like this:
    About Float and readLine() begginer problem.-math-game.jpg
    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;
        myFloat = Float.parseFloat(myInputStream.readLine());
    so the final code 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));
      //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));
          
          }
    
      }
    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
    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!!!

  2. #2
    Kaahrl is offline Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    5
    Rep Power
    0

    Default Re: About Float and readLine() begginer problem.

    May be to much explanation for so stupid problem....

  3. #3
    Kaahrl is offline Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    5
    Rep Power
    0

    Default 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. #4
    Kaahrl is offline Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    5
    Rep Power
    0

    Default Re: About Float and readLine() begginer problem.

    i see how to change the avatar now, thanksXD

  5. #5
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default 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. #6
    Kaahrl is offline Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    5
    Rep Power
    0

    Default 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:
    About Float and readLine() begginer problem.-new-error.jpg
    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;
    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));
          
          }
    
      }
    Thank you, by the way...

Similar Threads

  1. begginer needs help..?
    By lina in forum New To Java
    Replies: 4
    Last Post: 01-15-2010, 05:48 PM
  2. Receiving Text over a Socket (ReadLine() problem)
    By HermanHope in forum New To Java
    Replies: 1
    Last Post: 04-09-2009, 11:35 PM
  3. Begginer and project
    By Gym in forum New To Java
    Replies: 6
    Last Post: 03-24-2009, 02:30 AM
  4. Replies: 10
    Last Post: 01-17-2009, 09:30 PM
  5. problem with console.readLine()
    By thatguy in forum New To Java
    Replies: 1
    Last Post: 12-14-2008, 08:40 PM

Tags for this Thread

Posting Permissions

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