Implementing Sstandard Predefined Methods


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Implementing Sstandard Predefined Methods

  1. #1
    Join Date
    Feb 2005
    Posts
    18

    Implementing Sstandard Predefined Methods

    Can someone please help me with this program, I can not get it to work. Look at it and see if you can tell me what I am doing wrong and what I need to do to fix it. Thank you!

    import java.io.*;
    import java.lang.*;

    public class Numbersfixed
    {
    public static void main(String[] args) throws IOException
    {
    BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
    double x, y;
    String line;
    char again = 'y';

    while(again == 'y')
    {
    System.out.println("Enter a float number and I will tell "
    + "you:\n"
    + "the smallest whole number >= to the number,\n"
    + "the largest whole number <= to the number, \n"
    + "and the absolute value of the number.\n");
    x = Double.parseDouble(keyboard.readLine());
    y = Double.parseDouble(keyboard.readLine());
    Math.max(x,y);
    Math.min(x,y);
    Math.abs(x,y);

    System.out.println("\nThe smallest whole number greater than "
    + x + " is " + Math.max(x)
    + "\nThe largest whole number less than " + x + " is " + Math.min(x)
    + "\nThe absolute value of " + x + " is " + Math.abs(x));
    System.out.println("Do you want to enter more data? y/n ");
    line = keyboard.readLine();
    again = line.charAt(0);
    again = Character.isLowerCase(line);
    }
    }
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I think you will want to use the Math.floor and Math.ceil
    methods, - and the abs does not take two arguments.. And when that is said; why two input values ?, it
    doesn't make sense according to your text message.
    eschew obfuscation

  3. #3
    Join Date
    Feb 2004
    Posts
    541
    System.out.println("Enter a float number and I will tell "
    + "you:\n"
    + "the smallest whole number >= to the number,\n"
    + "the largest whole number <= to the number, \n"
    + "and the absolute value of the number.\n");
    x = Double.parseDouble(keyboard.readLine());
    y = Double.parseDouble(keyboard.readLine());
    Math.max(x,y);
    Math.min(x,y);
    Math.abs(x,y);
    In addition, what are the methods in bold doing there? Those methods return a value, so calling them like that is not actually doing anything. They will return the value, and nothing is done with that value.

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Yes indeed, (what we used to refer to as 'throwing it on the floor'). There is definitely some cavities in the understanding of the procedural elements here....
    eschew obfuscation

  5. #5
    Join Date
    Feb 2005
    Posts
    18
    thank you for your input. i do not know why those methods are there in that way. I did not write it like that, that is how the book had it. i was wondering if you could tell me why they had it like that lol. thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center