Int and Double help

I have a new lab and have most everything down right except that I am trying to create an int array that has double methods within it here is what I have so far:
       public static void main(String[] args) {
               Scanner in = new Scanner(System.in);
               System.out.print("How many numbers? ");
               int numNum = in.nextInt();
               System.out.print("How many intervals? ");
               int intervals = in.nextInt();
               System.out.print("\nHistogram");
               System.out.print("\n--------------------------------------------------------");
               double[] n = Generator.getData(numNum);
               double min = getMin(n);
               double max = getMax(n);
               double range = max-min;
               double width = (range/intervals);
               int[] histogram = new int [intervals];
               for(int index = 1; index <= intervals; index++){
                       if(index <= intervals){
                               histogram[index] = ();
               for     (int i = 1; i <= intervals; i++){
                       System.out.print("\n   " + i);
                       System.out.print(" " + range);
               System.out.print("\n--------------------------------------------------------");
       private static double getMin(double[]n){
               double lowest = n[0];
               for (int index =1; index < n.length; index++){
                       if (n[index] < lowest){
                               lowest = n[index];
               return lowest;
       private static double getMax(double[]n){
               double highest = n[0];
               for (int index =1; index < n.length; index++){
                       if (n[index] > highest){
                               highest = n[index];
               return highest;
       private static int getArray(double[]n,double intervals, double width){
               int[] array = new int [intervals];
               for(int index=0; index <= intervals; index++ ){
                       if(index <= intervals){
                               array[index] = (n[index]/width);
               return array;
       }I am stuck of the getArray class. Any help is greatly appreciated.

haphilli wrote:
I appreciate the help I am still just not getting it it is supposed to return this:
How many numbers? 100
How many intervals? 10
Histogram
1 ****(4)
2 ******(6)
3 ***********(11)
4 *****************(17)
5 **************************(26)
6 *************************(25)
7 *******(7)
8 ***(3)
9 (0)
10 *(1)
The program performs the following actions:
1. Ask the user to enter the number of numbers that will be generated and the number of intervals that will be used in the histogram, and input the two values;
2. Generate the required number of pseudo-random numbers by using the double[] Generator.getData(int n), which, given the number of numbers to generate, n, returns an array of double of size n containing the generated numbers;
3. Compute the range of data values (by finding the maximum and the minimum and taking their difference); then compute the width of each equally-sized interval (by dividing the whole range by the number of intervals specified by the user); finally, compute the number of data numbers falling in each interval and store these frequencies in an array of integers;
4. Output the histogram of the data as displayed in the sample run above: each bar starts with an index (1 through the number of intervals), followed by a number of '*' equal to the number of numbers in that range, followed by the number of '*' in parentheses.
Note: Pay attention to detail. Make your output look like the output in the sample run. However, note that your program must be able to produce the correct histogram for arbitrary data, not just for the specific data generated by Generator.getData().Yes, but we're thus far not addressing the proper operation of your code - we're still in the debugging phase.
After the code compiles cleanly, and you get all the obvious "mechanical" things fixed, then we can start addressing the design.
Why do I say that? Ordinarily the design comes first. But there are some syntax issues that really need to be addressed before you can appreciate what is wrong with the logic flow. You can work out the design in your head, but let's fix syntax errors before we code it up, so that we all have a good understanding of the the mechanicals.

Similar Messages

  • Dimensions - int and double mixed?

    Dimension x = new Dimension(int_1, int_2);
    int height = x.height;
    int width  = x.width;
    double height_d = x.getHeight();
    double width_d = x.getWidth();When you create a dimension you give it to integers as the width and height. However, if you call getHeight() or getWidth() it returns double-precision values. What's the point? Why does it use int/doubles?
    Thanks

    The methods getWidth/getHeight are inherited from RectangularShape.
    We have:
    Rectangle2D extends RectangularShape
    Rectagle extends Rectangle2D //implemeted with ints
    Rectangle2D .Float extends Rectangle2D //implemeted with floats
    Rectangle2D .Double extends Rectangle2D //implemeted with double
    So the implementations are providing the precision. Since the getWidth/getHeight methods are common
    to the hierarchy they return doubles to avoid loss of precision in the Rectangle2D .Double case.
    On the other hand, if I'm working with a java.awt.Rectangle I just access the public width and height fields
    directly.

  • Overloading ambiguity between "std::pow(double, int)" and "std::pow(long do

    hello all,
    we have a problem with sources coming from visual c++, i can reproduce the problem with the small code:
    $ cat test.cc
    #include <math.h>
    int main()
    double kk;
    int j11;
    j11=4;
    kk=pow(2,j11);
    $ CC test.cc
    "test.cc", line 8: Error: Overloading ambiguity between "std::pow(double, int)" and "std::pow(long double, int)".
    1 Error(s) detected.we are on linux, with sun studio 12u1
    thanks in advance for help,
    gerard

    The issue is whether the standard headers associated with the compiler have the overloads required by the standard. If the required overloads are present, the original call of std::pow is ambiguous, and the compiler will report it.
    If you have a recent version of Visual C++, I'd be very surprised if the function overloads were not available. Possibly you are using a compiler option, perhaps a default option, that hides the overloaded declarations. In that case, some C++ code that conforms to the standard would not behave correctly when used with the compiler in that mode.
    The correct approach is to use the compiler in standard-conforming mode so that code you write will be accepted by other standard-conforming compilers. That is, after all, the purpose of the standard.

  • Int, Double Help please

    Ok, I give up. I cannot figure out the most elementary of concepts here and am tired and frustrated.
    My code will not help the question so I won't waste space with it. Here is my problem:
    I am creating an applet to calculate fabric yardage. I need to be able to read in the input which will either be an int or a double/float to 2 decimal places.
    I will then use that to calculate yardage using a numberOfStrips * width style equation. This equation will need to be rounded up to the nearest integer, thus, a 2.34 will need to go up to a 3 not down to a 2.
    I have tried every combination of float, double, int and cannot figure this out. I cannot use the double.parseDouble() to read in a double because Netscape will not recognize it and any time I attempt to cast to a double from an int, or vice versa, I just get 'loss of precision' errors from compilers.
    I am giving up for now but I hope someone can help me figure this out. (Why don't they teach real world stuff like this in classes!)
    TIA

    I don't understand what you mean by "I cannot use the
    double.parseDouble() to read in a double because
    Netscape will not recognize it" so I can't help
    there.Wow, thanks everyone, I wil try these suggestions. when I was trying to use double.parseDouble() in netscape (communicator 4.78), it just doesn't do anything. It loads the applet, but when I press the button, nothing.
    I found on another site, the O'Reilly site, and it said that Netscape doesn't recognize Double without the plug-in. Problem is, I am trying to install the plug-in, and it doesn't find Netscape as a browser option. Ugh. I have to assume that this will work for all users so if it crashes on Netscape, need to figure out how to get around that.
    I will try these suggestions.

  • My trackpad in Macbook is not working properly. The tap and double tap is not working but other gestures are working. Please help me..thanks

    My trackpad in Macbook is not working properly. The tap and double tap is not working but other gestures are working. Please help me..thanks

    Portables and Magic Trackpad: Jumpy or erratic trackpad operation
    Might be something from that link that will help.

  • Help with unsigned ints and how to store and retrieve data in them

    Hi all
    I have a problem where some data is being stored in an unsigned int
    i dont really know much about them and am unsure on how to go about using the data.
    The data being stored in them is row and column information in an excel spreadsheet.
    The method is passed through 2 ints (column, row) and then a unsigned int is created out of these two values
    the column is 8 bits and shift to the left hand byte (column & 0xFF <<24)
    the row is 16 bits shifted to the right of the column (row & 0XFFFF <<8)
    so if the column and row were 1,1 then the unsigned int would be
    16777472
    and for 1,2 then it would be 16777728
    (i dont actually know how these numbers are formed, it would be great if someone can explain this too :) )
    anyway now i have those unsigned int numbers does anyone know how i would go about taking that unsigned int and getting my int back from it
    so take 16777728 and extracting column 1, row 2
    any help would be appreciated

    its not a 3rd party product, its been written by
    another peep who is on holiday for 2 weeks so im
    trying to sort something out but dont really
    understand unsigned ints and stuff :(This is what is called a "third party product". It's not written by Sun, and it's not written by you.

  • String to Int and Int to String

    How can I convert a string to Int & and an Int to String ?
    Say I've
    String abc="234"
    and I want the "int" value of "abc", how do I do it ?
    Pl. help.

    String.valueOf(int) takes an int and returns a string.
    Integer.parseInt(str) takes a string, returns an int.
    For all the others long, double, hex etc. RTFM :)

  • How to change the waveform-type inside of the waveform graph from int to double?

    Hello,
    attached you find a vi with two waveform-graphs.
    When i rightclick them and select "create constant" then it creates the constant.
    The difference between the two graphs is, that one creates a double-array inside the constant and the other graph creates an int-array inside
    The question is: Where can i change inside of the int-graph that it also creates a double-array in the constant?
    (Problem is that all double-waveforms send into this graph are changed to int and rounded in the display)
    Thanks for the help
    Attachments:
    waveform.vi ‏27 KB

    The datatype of a chart or graph is determined by the last thing you wired to it.  By default, they are simple doubles or arrays of doubles.  My guess is that you first wired a waveform with an integer data type to the graph.  It should switch automatically to a double waveform graph if you wire a waveform which contains double data to it.  If it does not, that is probably a bug.  If you have a VI in this state, please post it and I will report it to R&D.
    Thanks!
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Outlook 2010 apostrophe, single and double quotes are changes to question mark while sending mails to other internet receipient.

    We are using MS Outlook 2010 as our mail client. But we have noticed that whenevr we sent a mail to any other internet mail recipient all the "apostrophe", "single" and "double quotes" have automatically converted to ?. We have
    done almost all the workaround found in this site such as
    1.New a message and focus on the message window > click File > Options > Mail > Spelling and Autocorrect… > Proofing > AutoCorrect Options… > AutoFormat > clear the box before “Straight quotes” with “smart quotes”
    2. Used different encoding. We presently using US-ASCII for outgoing message. etc.
    Need your help to sort out these issues urgently.
    Waiting for a solution.

    Hi,
    What is your account type? IMAP, POP or Exchange?
    Send an email from the webmail, ask the recipient if this issue persists.
    As far as I know, this problem is always related to the encoding for outgoing messages, and here I suggest you try UTF-8:
    Go to File -> Options -> Advanced -> International options -> Uncheck "Automatically select encoding for outgoing messages", then select "Unicode (UTF-8)" beside "Preferred encoding for outgoing messages" -> OK.
    Hope this helps.
    Regards,
    Melon Chen
    TechNet Community Support

  • No DNS and Double NAT

    Hello, I've recently encountered a very frustrating bug in my system that I could use some help troubleshooting.  I've read several similar posts, some are resolved while others are not, however none of the resolutions have worked for my situation.  Here it goes:
    I have an old macbook pro, a new macbook air, a white macbook and 2 iPhone 4s's all connected to the internet via WiFi through an AirPort Extreme.  The AE is connected to a cable modem which has internet service through Cablevision in NY.  There is also an AT&T Microcell hooked up to the AE to boost my cell signal.   All of this equipment has been working flawlessly together for a long time.  Until recently.  It could have started after an update, there have been several lately on all of the equipment including the firmware in the AE.  Anyway, I'll be connected without any issues - all lights green and happy - when suddenly, the internet will drop off and the AirPort Utility will pop up and warn me that:
    1) On the "internet" icon, it will say "disconnected"  
    2) On the AE icon, it says "No DNS server and Double NAT"
    After a few minutes and nothing done on my part, the lights turn green, the internet reconnects and all is well again. 
    This happens frequently and is really beaching a nuisance.  Due to the frequency of the disconnection, I can no longer download a large file, update, or anything.  Streaming video is impossible.
    So far, I have tried bridge mode and cycled the power in the order recommended to no avail.  When I do that, the AE turns green, but the internet says "not connected".  I have also read that there might be too many IP addresses which is not sitting well with my ISP, so I disconnected everything including unplugging the Microcell.  Lastly, there are no other wireless phones or devises in the house.  All to no avail.
    I should also mention that this began occurring on my Time Capsule, which I replaced with the AE in an attempt to fix this issue. 
    Any help would be greatly appreciated.
    Joe

    Sounds very similar to what I've been trouble shooting for 2 months now, only I have DSL from AT&T and I don't see the Double NAT warning.  My last post on the problem is here. 
    My only emergency solution for getting by day to day on the internet is to unplug the AE and connect one Mac directly to the DSL modem.  There's no shared connection or WiFi.  I looked at hosting WiFi from the Mac, but the only security available with that is WEP which isn't considered secure.  Even with this set up, I think (seat of the pants) that there are quality of service problems. 
    I've replaced the Airport Extreme with 2 different new units and the DSL modem with a new unit to no avail.  The Genius Bar and Apple phone support couldn't solve this, nor have 2 calls to AT&T support and one visit from an AT&T repairman.
    I would like to know how to better test or quantify the poor quality of connection that seems to be the problem.

  • Printer suddenly started printing blurry and double vision like

    Printer suddenly started printing blurry and double vision like. I have cleaned all i can and aligned the printer heads muliple times, but no difference

    I did a quick search and came across this. Although it is for a 432, hopefully this imformation helps as canon printers are assembled relatively simular.
    http://forums.usa.canon.com/t5/Printer-Multifunction-Support/I-had-a-paper-jam-on-my-MX432-and-since...
    MY EQUIPMENT:
    EOS Rebel T4i
    EF-S 18-55mm f/3.5-5.6 IS II
    EF-S 55-250mm f/4-5.6 IS II
    (2) B+W 5.8 010 UV - Haze 1x MRC (F - PRO Series filter)
    HOYA 58mm HMC Multi-Coated ND8 Filter

  • I am changing laptops and have tried to download and install Acobat 9 Standard from the Adobe website, but get message that my serial number is invalid. I log in and double check my account and it shows as a valid serial number.  Now what?

    I am changing laptops and have tried to download and install Acrobat 9 Standard from the Adobe website, but get message that my serial number is invalid. I log in and double check my account and it shows as a valid serial number.  Now what?

    If you had it on a laptop that crashed and you threw away, it is still considered as activated on that machine.  YOu should contact Adobe by chat or by phone and have them deactivate for you.
    Here is a link to a page with options to help make contact:
    http://www.adobe.com/support/download-install/supportinfo/
    If you are getting a message that indicates the serial number is not valid, you should look thru the following:
    Error "The serial number is not valid for this product" | Creative Suite
    http://helpx.adobe.com/creative-suite/kb/error-serial-number-valid-product.html

  • How do I set Firefox to automatically open downloads instead of having to go to my downloads and double click to open?

    Whenever I have used Firefox on a PC it at least gave me the option to open certain file types automatically. I download a lot of files and the time adds up when I have to open the downloads box and double click on the file each time.

    Hi,
    This could help you: [https://support.mozilla.org/en-US/kb/Managing%20file%20types#w_changing-download-actions Changing download actions]

  • Does anybody know any software for the Mac that I can run round robin, single and double elimination tournaments?

    Does anybody know any software for the Mac that I can run round robin, single and double elimination tournaments?  I help run tournaments but using excel for pool play and the web for bracket play, but if wifi is not available I have no way of running brackets for prize play.  Can some one help point me in the direction of software that I can use locally on my Mac Pro. 
    Thanks,
    Chris
    <E-mail Edited by Host>

    Splendid City Team Sports Scheduler, and Sports Scheduling Software System

  • How do you test if a string could be a valid int and then convert to int?

    Hello, my name is Esran41 and I'm new to this site. I'm in computer science one this year and our current assignment is to make a console based Tic-Tac-Toe game. The final program must be able to detect errors in the user's input. For example, if the program asked the user for an int and he typed a character, our program must recognize this, print an error message, and then prompt him for the int again. I also need to know some common string manipulation methods(like String.length) and their syntax too. Again, I'm extremely new to java, so please include code fragments and example programs to demonstrate these methods.
    To sum-it-up, I need to know how to do the following(The syntax):
    Method (1)
    - test an inputed string to see if it's a valid integer
    - report an error to the user if it's not a valid integer
    - if there was an error, prompt the user again
    Method (2)
    - Pass the inputed string as a parameter
    - Convert the string into an integer
    - return the integer
    Also, what is a try-catch statement, what does it do, and how is it implemented?
    Please post any advice or help that you may have pertaining to my problems.
    Thanks!

    Do not insult me. If I could read my computer science
    book, I would. Please don't insult yourself... by pointing out your limitations...
    I will apologize for my cynical remarks... You should see how many requests for " I need help" where the answer could be found so easily...
    But it is quite obvious that you have access to the internet... If you did a search for Java, eventually you would find yourself as Sun's web site... Which means that you would have arrive at this page...
    http://java.sun.com
    and towards the bottom left had corner of that page you would find these links...
    Learning
    New to Java Center
    - Tutorials & Code Camps
    - Online Sessions & Courses
    - Course Certification
    - Instructor-Led Courses
    - Quizzes
    And you will find the same resources that I am using to learn Java...
    I'm looking up this information not only for myself, but for my class too....
    Thus, we are stuck with old computers, about twenty books for 220 kids, and one teacher who is great at >C++, but knows nothing about java.Then print out the Java documentation, goto Kinko's and make copies so that your class can have the reference material available to them, or ask your teacher to... Since he/she will need to learn the language also... But since they have programming experience they will be better able to explain the concepts of programming that you do not understand...
    You can make any excuse for why it is difficult for you to learn, but in the end its totally irrelevant... If the school district cannot provide funding for class material, then instead of complaining with " I don't have a book... " start a community fund raiser to purchase those materials... Goto to the public library and see if they have resources you and your class can utilize... After all, it is your responsibility to educate yourself...
    And most important of all, never ever say anything negative or limiting against yourself...
    Do not insult me. If I could read my computer science book, I would. This is a statement against yourself... What does this statement tell you about yourself... You stated that I should not judge, but here you made a judgement about your own ability to learn...
    To even insinuate that I skip class is an outrage to me. You should watch your tongue and not be so >quick to judge a situation.Why, do you ? Apparently I touched a nerve somewhere... But that does not matter...
    Are you really concerned with what I think of you... If you are then you are a fool...
    What other think or say have nothing to do with you... Do you know me, do I know you...
    The answer is clear... I can give it to you... The Answer is No.
    If you want to learn then learn... Read, Research, Practice and Read again... So simple...
    Anyway... Have fun... Check out the tutorials, learn how to use the API documentation and practice coding...
    and here are those links again...
    The Java Tutorial
    http://java.sun.com/docs/books/tutorial/index.html
    Essentials of the Java Programming Language: A Hands-On Guide, Part 1 and 2
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/
    Language Essentials Short Course
    http://java.sun.com/developer/onlineTraining/JavaIntro/contents.html
    Others
    The Java Tutorial
    http://java.sun.com/docs/books/tutorial/index.html
    Tutorial Index
    http://java.sun.com/developer/onlineTraining/index.html
    - MaxxDmg...
    - ' He who never sleeps... '

Maybe you are looking for