What I am doing wrong in this loop?

How I can change this code
to get the result like this

If the user, enter the number of hours travelled = 3
and please enter the speed of the vehicle in miles per hour = 40
the method computes 1 * 40
2 * 40
3 * 40
I need to use the loop
Thank you, I am just learning JAVA

I need the output to look like this

/*
* Description Convert distance settings: Int: speed, number
* hours traveled (milePerhour, numberOfhoursTraveled, distance)
* Performance: integer: Distance
*/
public static double convertDistanceTraveled (int milePerhour, int numberOfhoursTraveled) {}
return (milePerhour * numberOfhoursTraveled);

public static double convertDistanceTraveled (int c) {}
int dist = milePerhour * c;
return dist;
}
}
Edited by: 893973 on Oct 18, 2012 1:37 PM

Edited by: 893973 on Oct 21, 2012 4:24 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

Hello

Try changing your loop as follows:

for (int i = 1; i)<=numberOfhoursTraveled;>
{
System.out.format ("%s\t\t%s\n", I, convertDistanceTraveled (milePerHour, i));
}

Also change the return type for the function convertDistanceTraveled of the House double int.

Hope this helps,

Thomas

Tags: Java

Similar Questions

  • What am I doing wrong with this loop?

    It drives me crazy! I am trying to create 100 triangles, like a little challenge for me, in random positions.

    import flash.display.MovieClip;

    addEventListener (MouseEvent.CLICK, 100Tri)

    function 100Tri() {}

    for (var i: int = 0; i > 100; i ++ ;)) {}

    var positonX:int = Math.random () * 550;

    var positonY:int = Math.random () * 400;

    var triangle: MovieClip = new Triangles();

    triangle.x = positionX;

    triangle.y = PositionY;

    addChild (triangle)

    }

    But he returned as a constantly

    Scene 1, Layer 'AS', frame 1, line 21084: syntax error: expected rightparen before sorting.
    Scene 1, Layer 'AS', frame 1, line 31084: syntax error: expecting identifier before 100.

    There is a class named 'Triangles', which is related to a movieclip of a triangle. It contains nothing, but what is in all classes.

    Help? I'm sure it's just a little thing miss me, but its annoying me. >. <

    Hello

    There are a few stupid errors in your code. Use it below:

    import flash.display.MovieClip;

    stage.addEventListener (MouseEvent.CLICK, triangles)

    function triangles(e:MouseEvent)

    {

    trace ("click handler")

    for (var i: int = 0; i > 100; i ++)

    {

    var positonX:int = Math.random () * 550;

    var positonY:int = Math.random () * 400;

    var triangle: MovieClip = new tri();

    triangle.x = positonX;

    triangle.y = positonY;

    addChild (triangle)

    }

    }

    Kind regards

    Vipul

  • What I am doing wrong in this little pl/sql statement?

    Hi all

    I'm happy to write in this forum for the first time. Can someone help me show what I'm doing wrong in this little summary:

    create or replace procedure augmente_salaire (employees.employee_id%type IN p1, p2 IN number (3))

    is

    Update employees set salary = salary + salary * p2/100 where employee_id = p1;

    end augmente_salaire;

    Start

    augmente_salaire (1001,20);

    end;

    I use pl/sql developer.

    Any help would be appreciated.

    Best regards.

    Hello

    Welcome to the forum.

    You missed a BEGIN block after the IS. Between IS and BEGIN, you declare your variables.

    And the parameter should be the NUMBER instead of number (3).

    Do you get an error message when you tried to run your code?

    Concerning

    Marcus

    Post edited by: Marwim

  • What am I doing wrong with this idea of menu?

    Hi team,

    I am trying to build a menu but have two problems, as you can see on the vid when I press one of my button fly, closing at all (which could be authorized)

    Quen worst is that even if I have the names of instance for all the steps and the target tool allows you to find the path to these buttons, I can't access it from the main timeline.

    Here's the code...

    import flash.events.MouseEvent;

    import flash.display.MovieClip;

    GSmain.gsshape.gss1.gssr1.addEventListener (MouseEvent.CLICK, page2go);

    function page2go(e:MouseEvent) {}

    gotoAndStop (2);

    }

    and the error...

    TypeError: Error #1009: cannot access a property or method of a null object reference.

    to aavar / frame1 () [aavar::frame1:4]

    aavar is the document class associated with this file

    If

    GSmain.gsshape.gss1.gssr1.addEventListener (MouseEvent.CLICK, page2go);

    is frame 1/4, GSmain.gsshape.gss1.gssr1 does not exist when this code runs.

    you have also nested named functions which is always problematic:

    function whatever() {}

    function whatevernested() {}

    }

    }

    should be

    function whatever() {}

    }

    function nolongernested() {}

    }

  • What am I doing wrong with this simple table?

    I have a table that I need to add unique characters to slowly.

    If the table is wordToCheck and I have a few "drop places" to check and see if a letter "fell off the coast." An index is assigned to each point of fall and I just want to add the letter to the appropriate index of the table so that I can push in a string.

    This is my code:

    wordToCheck [currentBlank.register] = currentLetter.letter.toLowerCase ();

    So you can see that if 'A' has been abandoned to the empty spot with the 2 register it would return "-a".


    The problem is that it is remove each time that I add a letter. If I put 'A' in the registry and then 2 "M" save 3 it returns '-m '.

    How do it do not replace itself every time?

    1. to the original post: If you use the same instance of table - it shouldn't happen. Looks like whenever you add letter - it's a new instance of the wordToCheck table.

    2. If you want to convert the string table - use Array.join () method.

  • I want to create a photomerge. The dropdown under 'Enhance' for this option does not appear. What I am doing wrong?

    I want to create a photomerge. The dropdown under 'Enhance' for this option does not appear. What I am doing wrong?

    What version of PES do you have?

    In PSE14, we moved the entry point for the function Photomerge in the guided view edits.

    In this bar at the top of the editor, click on guided, and then there will be a number of category tabs at the top. Click on Photomerge, and you should be good to go.

    See you soon

    Bob

  • Call my Subvi? what I am doing wrong

    Hello people

    I'm trying to create a simple program to read data from 3 channels, I created a main VI for the GUI and a Subvi allow the user to choose what channels he would like to make a link to the lights on the front panel.

    I did something that s look like what I joined, but I have the following problems:

    Sometimes and not all the time when I opened the main VI, I find the Subvi opening automatically without pressing the call button, in this case, I find already pressed the OK button and I can't close the Subvi, it happens all the time if I joined the vi one program exe.

    If the Subvi has been called, if try to close it with the close 'x' windows key all freeze in primary vi.

    I also tried adding other similar loops with two subvis to settings for other digital channels, and the same thing happens with them.

    what I am doing wrong.

    Thanks in advance

    There is an event for the Connect button that runs when you press it. It will be connected, but only if the Boolean value in the shift register is true, i.e. If you have configured channel settings once. If you tap on connect just after the start of the program, it does not connect.

    If you want a different behavior, you can leave out the Boolean value completely and initialize the shift register for example with default string parameters. I have fieldpoint, so I can't do right now.

  • I can't update Flash player. What I am doing wrong?

    I can't update Flash player. What I am doing wrong?

    I currently have version 21, 22 version is the latest.  I get.

    "Adobe Flash Player could not be installed."

    I did the troubleshooting steps below. Everything is good, as I can tell.

    https://helpx.Adobe.com/Flash-Player/KB/enabling-Flash-Player-Firefox.html

    My Shockwave Flash is set, 'always on '.

    I ran the Adobe flash installer which seems to be successful. Then, I tried a new facility, still no joy.  (He did remove Flash Player version 21, now I have nothing.)

    Suggestions appreciated

    Firefox could block Flash because of security concerns.

    Because of security problems in older versions, Apple has

    updated the web plugin blocking mechanism to disable all

    earlier versions of Flash Player, 22.0.0.192 and 18.0.0.360.

    Information on web blocked plug-ins will be posted to:

    http://support.Apple.com/en-us/HT202681

    The question you should ask is why you have Flash installed. You don't need Flash. If you have not installed Flash, videos will play in HTML5. If the video requires Flash, you can use Google Chrome to play.

    From Sierra, Safari will be is more said websites common plug-ins are installed. It does this by not including not information on Flash, Java, Silverlight and QuickTime

  • I have type in a new web site in the address bar. Press enter, nothing happens? Went to internet expl. ORER and tried. It worked. Uninstalled Mozilla twice. reinstalled. Still, the address bar does not go to the new site. What I am doing wrong?

    I type in a new web site in the address bar. Press ENTER. Wait. Wait. type in the same new website in the search bar. It goes straight. Uninstalled Mozilla twice. Reinstalled. Tried to go to a new web site. you press on enter. Nothing. What I am doing wrong? I tried this procedure in Internet Explorer and the new address was excluded.

    Hi markehrmann,

    I'll try from Firefox Firefox to solve the issues in Safe Mode. If you do not have the issue so that all your modules, extensions, and themes are disabled, you can try adding them in one by one until you find the culprit. You should look at the guide to troubleshooting Extensions and themes and article troubleshooting issues with plugins like Flash or Java to solve common Firefox problems as well.

    Hope this helps!

  • I have Firefox 5.0 is installed on my desktop and whenever I try to download or to save a file, that the Firefox Download Manager does not open. Why? What I am doing wrong?

    I am running Windows Vista on my desktop. I also have Firefox downloaded 5.0 on my pc.
    Whenever I try to download a software update or any type of file to the Firefox download box does not activate more as in the past.
    Why? What I am doing wrong?

    Options > general, make sure that "show the downloads window when downloading a file" is selected. See window Options - general Board

    Remember the download in the download window history, Options > confidentiality, "Remember download history" must be selected. See window Options - Privacy panel

    If this answer solved your problem, please click 'Solved It' next to this response when connected to the forum.

  • HWAT am I doing wrong with this webcam?

    Hello!

    I found a tutorial in a .pdf file on webcams, usb and how to make them work with labview... so... I managed to make this diagram below!

    But it still does not... What am I doing wrong? Or... you have a better scheme for this application? Or a diagram simple JAWS!

    Help! : s


  • The short films that I do in Windows Movie Maker fail to run after about 1 minute, regardless of the format, I save in (WMV or AVI) any ideas why or what I am doing wrong?

    The short films that I do in Windows Movie Maker fail to run after about 1 minute, regardless of the format, I save in (WMV or AVI) any ideas why or what I am doing wrong?

    I'm just looking to add the opening titles to the pieces of film of aprox 3 Germans, but everytime I try and save files for uploading to Youtube, then fail shortly after a minute. The sound and picture freeze while the counter continues until the end of the file.

    am driven crazy by this so any advice would be welcome...

    Hello

    My friend John Papa - MVP - is the expert on Windows Movie Maker.

    PapaJohn.org
    http://Papajohn.org/

    PapaJohn - online tutorials
    http://www.Papajohn.org/mm2-online-tutorials.html

    Windows Movie Maker Tutorials - see the menu on the left and others on the main screen.
    http://www.windowsmoviemakers.NET/tutorials/

    Windows Live Movie Maker Forums are good sources of information:

    Windows Live Movie Maker that works on Vista and Windows 7, see the link under Windows Live Essentials.
    http://windowslivehelp.com/

    Windows Live - Movie Maker Portal - official support Site - see also the Forums of the right part of the page
    http://windowslivehelp.com/product.aspx?ProductID=5

    ====================

    These might help:

    Getting started with Windows Movie Maker

    Import video, photos and audio on Windows Movie Maker

    Import video from a videotape

    Get a movie in Windows Movie Maker

    Make a movie quickly in Windows Movie Maker (AutoMovie)

    Publish a movie in Windows Movie Maker

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle=""><- mark="" twain="" said="" it="">

  • Overview of application icon - what am I doing wrong?

    I have read the kbase article and examined for messages but when even did not quite understand how flipping properly application icons.  I found the kbase article got halfway there and it seems to work, but not as I know reading the article.  I don't know that I'm doing something wrong.  I use Eclipse with v4.5 with a 8330 Simulator to test.

    Here's what I do now:
    Once completed the main application, I created a second application without code.  It is defined as another point of entry to my main application, has done started TICKING Autorun feature and has a png set in the project properties for the application icon.  It is also to pass the text "mistletoe" as an arg for the hand of my main application Sub in the properties of the application.

    In my main application, I have configured to be a system module in the properties of the application (don't think it was mentioned in the kbase article but if not then an icon shows the main application and the app of reversal) and added a similar to the following code in the Sub main.  According to the kbase article the bitmap/homescreen lines should be in another statement, but I moved it because of the problem I'm having (explained below).

    Public Shared Sub main (String [] args) {}
    Icon bitmap = Bitmap.getBitmapResource ("rollover.png");
    HomeScreen.setRolloverIcon (icon);

    If (args! = null & args.length > 0 & args [0] .equals ("gui")) {}
    new PhoneBookApplication () .enterEventDispatcher ();
    }
    }

    The problem

    As I said, it works, but according to the debugger 'mistletoe' text is passed to the Sub main of main application on AutoPlay and when the application is opened manually (shouldn't be my reading of the article) which means that the 2 lines of flipping that should be in the else statement were never executed.  Placing them out of the if it works correctly (even if the FI is not necessary at this stage because the condition is always true).  I'm surprised that the application attempts to start the application during automatic execution of the bearing another entry has no or a mistake or to launch the application but it has no the debugger indicates he's going through these lines of code (watch).  Can someone tell me what I am doing wrong?  I know it works, but I'd rather do it properly.

    Thank you

    Tim

    The problem seems to have been the line:

    HomeScreen.setRolloverIcon (icon);

    If I use the method call to an index, it works perfectly:

    HomeScreen.setRolloverIcon(icon,1);

    My first try at the top was obviously incorrect, but this correction and with the changes in the second post everything seems to work perfectly.  I don't know why it does not work without the index because this is what is shown in the samples.  A problem introduced in 4.5?

  • get the ora-01830, but cannot say what I'm doing wrong

    Hi, Oracle 11g R2.

    Could someone help me understand what I'm doing wrong in following select clause? I'm trying to convert the difference in seconds to hh.

    ISN.snapshot_ts and iobd.bd_handshake_ts are TIMESTAMP (6) WITH ZONE SCHEDULE

    Select to_date ((to_date (to_char (isn. )))) snapshot_ts , 'HH24:MI:SS DD/MM/YYYY'), ' MM/DD/YYYY HH24:MI:SS')

    - to_date (to_char (iobd. )) bd_handshake_ts , 'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'))*60*60*24, 'sssss')

    Hello

    Back-and-forth conversion as

    TO_DATE (to_char)

    are almost never necessary in Oracle.  There are a lot of built-in functions and features that make everything you need more simply.

    If you subtract one TIMESTAMP on the other, the result is an INTERVAL DAY TO SECOND.

    If you view an INTERVAL DAY TO SECOND, it is formatted as

    + 00:01:10.879000 000000000

    which is what you want.  In fact, it's what you want and then some others, which can be a problem for you.  If you are certain that the difference will be less than 24 hours, you can display the number of days in the beginning, and you're neither to display fractions of a second at the end.  In this case, you can convert the INTERVAL DAY TO SECOND string and then use SUBSTR (or similar) to get exactly the parts you want.

    Try something like:

    SELECT isn.snapshot_ts - iobd.bd.handshake_ts AS diff

    ...

    If this isn't what you want (or close enough) then after a small example of data (CREATE TABLE and INSERT statements) and the accurate results you want from these sample data.

    Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?

  • The dashed lines in my Illustrator file deform when I copy/paste the in Excel. Otherwise, the image is fine. What I am doing wrong?

    The dashed lines in my Illustrator file deform when I copy/paste the in Excel. Otherwise, the image is fine. What I am doing wrong?

    The lines end up looking much bigger than they were initially.

    I am using the paste special option in Excel and it works fine for all parts of the image, but this.

    Someone suggested I try to use the Mode plotted, but who has not made a difference when I tried.

    The map view wouldn't make any difference, so more clarification is needed on your workflow.

    Why it's not working for you save the image as a png image in Illustrator and then insert it correctly as a picture in Excel?

    What are you trying to make to it after that's in Excel? If the PNG workflow does not work for you, then explain your workflow. It might help to know if you're Mac or Windows and the version numbers and maybe screenshots.

Maybe you are looking for