Search:

Type: Posts; User: djl1990

Search: Search took 0.08 seconds.

  1. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    Sorry, I do try and explain steps though. I wont post code solutions in future.
  2. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    Try this mate




    int A, B;
    double C, D, E;
    Scanner scan = new Scanner(System.in);
    System.out.println("Please enter 2 integers:");
    A = scan.nextInt();
  3. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    You'll need 5 variables

    A & B (the two integers read in from user input)
    C = A parsed to a double
    D = B parsed to a double
    and E = C / B

    Try it that way.
  4. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    The key point learnt here i think is converting the ints to doubles before performing the division.
  5. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    Yes you should try my code above to see if its what youre looking for.

    I had the same problem with dividing two integers and trying to just store the result as a double.

    it just gave 0.0...
  6. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    Ah i think its parseDouble you need to convert int to double.

    at the moment i have:



    package testing;

    import java.util.Scanner;
    import java.text.DecimalFormat;
  7. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    to read in user input you need to use the Scanner class.

    first of all import the Scanner class: import java.util.Scanner;

    then in your main class body you want to create a new scanner object...
  8. Replies
    15
    Views
    1,761

    Re: simple arithmetic problem

    so you want to ask the user to type in 2 integers?

    then divide the first integer by the second integer? and store this value in a double.

    then print out the double to 2 decimal places?
Results 1 to 8 of 8