Output Problem with my problem help please

Here is the Instruction to the problem:
An interesting problem in number theory is sometimes called the ?necklace problem.? This problem begins with two single-digit numbers. The next number is obtained by adding the first two numbers together and saving only the ones-digit. This process is repeated until the ?necklace? closes by returning to the original two numbers. For example, if the starting numbers are 1 and 8, the output would look like:
18976392134718
and below is my program:
public class Necklace
     public static void main(String[] args)
          int f, s, sum, n, p;
          String first = JOptionPane.showInputDialog ("Enter first number:");
          String second = JOptionPane.showInputDialog ("Enter second number:");
          f = Integer.parseInt (first);
          s = Integer.parseInt (second);
          sum = f + s;
          n = sum % 10;
          p = s;
          while (!(p == f && n ==s))
               sum = n + p;
               p = n;
               n = sum % 10;
          String output = f +""+ s +""+ ++n+"";
          JOptionPane.showMessageDialog (null, output, "Necklace", JOptionPane.INFORMATION_MESSAGE);
My problem is that I don't know or have any idea how to make the output so it will show all the numbers in between, my ouput it only show the first 3 number, 1 8 and 9

My problem is that I don't know or have any idea how to make the output so it will show all the numbers in between, my ouput it only show the first 3 number, 1 8 and 9Hello and welcome to the forum. First and foremost, please use code tags when posting code here so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [code] below your pasted code like so:
[code]
  // your code goes here
  // notice how the top and bottom tags are different
[/code]For instance, here is your code with tags:
import javax.swing.JOptionPane;
public class Necklace {
   public static void main(String[] args) {
      int f, s, sum, n, p;
      String first = JOptionPane.showInputDialog("Enter first number:");
      String second = JOptionPane.showInputDialog("Enter second number:");
      f = Integer.parseInt(first);
      s = Integer.parseInt(second);
      sum = f + s;
      n = sum % 10;
      p = s;
      while (!(p == f && n == s))
         sum = n + p;
         p = n;
         n = sum % 10;
      String output = f + "" + s + "" + ++n + "";
      JOptionPane.showMessageDialog(null, output, "Necklace",
               JOptionPane.INFORMATION_MESSAGE);
}Next, you can declare your output String before the while loop, and then concatonate a new int on to this inside the loop. Perhaps an even better way is to use a StringBuilder object.

Similar Messages

  • My imessage isn't working when i send messages to people with iphones that have imessage it works with very few people, now it's starting to stop working with those people. help please.

    my imessage doesn't work between my friends and i. i have a new iphone 5. my messages only work with some people. with others imessage doesn't work in the first place and now its starting to stop working with other people help please.
    & yes we all have imessage on.

    Hi there,
    I see that you are having IMessage problems. Some of the problems might be:
    - Your friends IMessage is not activated (you have to activiate it with your apple id)
    - Your IMessage is not activated
    Here is some links to another person`s Imessage problems:
    https://discussions.apple.com/message/17301880#17301880
    https://discussions.apple.com/message/20142285#20142285
    https://discussions.apple.com/message/18988318#18988318
    Hope that helps!

  • After mixing a project i select bounce and burn the disc that is burned plays on any cd player but when i try to burn the wav or mp3 file that was created the resulting disc will only play in a computer this also happens with video projects help please

    after mixing a project i select bounce and burn the disc that is burned plays on any cd player but when i try to burn the wav or mp3 file that was created the resulting disc will only play in a computer this also happens with video projects help please are there any settings i need to alter as it seems the wav or mp3 file i ceated is being converted to a data file somewhere between the folder and disc drive

    Same thing for a movie file.. If you want to play back the movie via a DVD and a DVD player you must create a Movie DVD  and not just burn files to a data DVD... as Data DVDs are just storage devices for files and therefore will only work with computers...
    Movie DVDs are special formats that include things like menus and special file formats.. so they can playback via a DVD Player...
    You will need a 3rd party DVD Burning app like Toast which is what i actually use.... or the more popular DVD Creator app...to create and then burn a Movie DVD that will playback on a DVD Player....
    https://answers.yahoo.com/question/index?qid=20101220205435AA70beb

  • My phone although fully charged has just switched itself off and won't turn back on again! I'm just coming to the end of a 2 year contract and never had any problems with it. Help please!

    My iPhone 4 although fully charges has just switched itself off and won't turn back on again. I've tried taking the sim card out but nothing happens. I'm just coming to the end of a 2 year contract and never had any problems with it before. Help please.

    Start here
    http://support.apple.com/kb/HT1430

  • After recent upgrades Firefox prevents links in several websites from working whilst there is no such problem with other browsers - help please.

    Since a recent upgrade of Firefox links in several websites no longer work. They used to be fine and I loved Firefox. The problems do not exist with other browsers e.g. Internet Explorer, Google Chrome. More specifically, on talktalk.co.uk the links to news items do not work, nor do those to "My Account." On Barclays.co.uk the link to print my statement doesn't work - similarly on MBNA.com
    There are several suggested solutions around the internet but all are complex, none so far have worked and I don't see why I should need to carry out the suggested tweaks. Firefox used to be great - now it isn't. The problem seems to be with the upgrade. Please help me to get my Firefox to where it should be.

    Thank you but please don't waste any more time on this. I have done as I said I would - removed and re- installed Firefox, cleared all cookies and caches (CCleaner) - still doesn't work. As I said at the start, the problem is not confined to Talktalk - it applies to several other sites and links. The problem does not occur with Internet Explorer nor with Google Chrome so I am now using those.

  • Problem with my Macbook - HELP PLEASE!!!!!!!!

    Hello, and please help!
    This is my second 1.83ghz 1 gb ram 80 gb hard drive Macbook. The first one mooed and had a buzzy display. This one has been perfect for three weeks. Have loved it. But today, my girlfriend shut it down, apparently properly, we took it out of it's case to use it and the fan was on FULL blast. Even though the computer was off! It then wouldn't turn on for ages. The macbook was very, very hot at this point.
    Eventually it restarted when the fan went off ten minutes later. The battery level had gone from 80% to 28%. And then it said 'Mac OS X unexpetedly quit' and carried on as normal.... for the moment.
    My girlfriend said 'it's done it once before' too.
    Any heads up on this? Many thanks in advance.
    Paddy

    It definitly sounds like she instructed the computer to shut down, but did not wait for the Mac OS to actually shut off the computer befre closing the lid. Doing so suspends activity and puts the computer into sleep mode where it still uses power. If you put the computer in a bag, the heat will build up, and I would expect it do do as you described.
    Ask your girlfriend if she waited for the screen to turn black or not. If she did wait for the screen to turn black, then you definitly have a problem that should be taken up with AppleCare, or Apple.
    If this post was helpful, please mark it as such.

  • VIRUS PROBLEMS, HELP PLEASE???

    I continue to have messages popping up saying my computer is infected. It wants me to cleanup and I have to register with Mac Shield 2.6.  Pronograhic websites keep popping up.  Anyone having this problem?  Did not have this problem yesterday, but it's here today!  There is also a Red Sheild on the top of the toolbar where it shows the time, battery life, etc.  Right clicking on the sheild drops down Scan Now, Cleanup, Control Center, Scan, System Info, Settings, About, and Register.  A pron site just popped up again!  Need help Please!!

    Fuony wrote:
    The Mac Shield malware can come through Firefox too if you allow it to and you click on it!
    Your exactly right, it is possible that if you visit a site and need the scripts to run for something that the malware that uses Javascript is on that site, then your going to be presented with it.
    The thing is with the Firefox + NoScript combination defeats alot of the web side trickery the malware authors are using to get the malware to appear in the first place.
    Also this "MacDefender" isn't the only malware making the rounds. There are some serious Flash vulnerabilities being hosted on hostile/adult websites that are running scripts for no apparent reason other than to try to infect your machine.
    By running all scripts all the time, your computer is in a state as if you tried running across a busy highway blindfolded.
    As a lifelong "MacHead" I can understand Apple loyalty, but if Apple isn't cutting the mustard on their browser security, rather place their users security at serious risk for the sake of convenience, then I have to think about using and recommending to others something else that is more secure.
    As a example, I surf thousands of web pages a day, some on really nasty sites, yet I haven't seen this "MacDefender" appear on my computer. Even when I purposely visited links that people have submitted that had the malware. (I maintain a couple of bootable clones of my boot drive just in case)

  • Soundtrack problems - help please

    Help please. I tried doing a send to multi-track project from FCP with the base layer video option and kept getting the 'error sending selection to Soundtrack Pro' message. I did a search and the suggestion is that I have no disk space but I have over 600GB!
    Then I tried a send with the full video and the file saved okay. However when I try to open the .stmp file, Soundtrack Pro starts and then freezes. I've tried opening in various ways.
    Help please, I just cannot figure this out! What am I doing wrong?

    Not sure how much help this is, but since you're having problems with the layout, did you try deleting the layout file? MacintoshHD/users/username/Library/Application Support/Soundtrack Pro/Layouts
    BTW, I found a BKiLifeConfiguration.plist in the following path:
    MacintoshHD > Library > Application Support > ProApps > Internal Plug-ins > BrowserKit > iLife.bkplugin > Contents > Resources
    Do you find it there?

  • SQL INSERT problem - help please

    Hello,
    I'm having a problem with INSERT statement.
    There is a "ShowFinal.jsp" page, which is a list of candidates who selected from the second
    interview. The user picked some candidates from the list and conduct the 3rd interview. After
    he check suitable candidates(who are selected from the 3rd interview) from the list , enter
    basic salary for every selected candidate, enter date of interview and finally submit the form.
    These data should be save into these tables.
    FinalSelect(nicNo,date)
    EmpSalary(nicNo,basicSal)
    In this "ShowFinal.jsp" page, it validates the following conditions using JavaScript.
    1) If the user submit the form without checking at least one checkbox, then the system should be
    display an alert message ("Please select at least one candidate").
    2) If the user submit the form without entering the basic salary of that candidate which was
    checked, then the system should be display an alert message ("Please enter basic salary").
    These are working well. But my problem is how to wrote the "AddNewFinal.jsp" page to save these
    data into the db.
    Here is my code which I have wrote. But it points an error.
    "AddNewFinal.jsp"
    String interviewDate = request.getParameter("date");
    String[] value = request.getParameterValues("ChkNicno");
    String[] bs = request.getParameterValues("basicSal");
    String sql ="INSERT INTO finalselect (nicNo,date) VALUES(?,?)";
    String sql2 ="INSERT INTO EmpSalary (nicNo,basicSal) VALUES(?,?)";
    for(int i=0; i < value.length; i++){
         String temp = value;     
         for(int x=0; x < bs.length; x++){
              String basic = bs[x];
              pstmt2 = connection.prepareStatement(sql2);
              pstmt2.setString(1, temp);
              pstmt2.setString(2, basic);
              int RowCount1= pstmt2.executeUpdate();
         pstmt1 = connection.prepareStatement(sql);
         pstmt1.setString(1, temp);
         pstmt1.setString(2, interviewDate);
         int RowCount= pstmt1.executeUpdate();
    Here is the code for "ShowFinal.jsp".
    <form name="ShowFinal" method="POST" action="AddNewFinal.jsp" onsubmit="return checkEmpty() &&
    ValidateDate();">
    <%--  Loop through the list and print each item --%>
    <%
         int iCounter = 0; //counter for incremental value
         while (igroups.hasNext()) {
              Selection s = (Selection) igroups.next();
              iCounter+=1; //increment
    %>
    <tr>
         <td style="background-color:ivory" noWrap width="20">
         <input type="checkbox" name="<%= "ChkNicno" + iCounter %>"      
    value="<%=s.getNicno()%>"></td>
            <td style="background-color:ivory" noWrap width="39">
                 <%= s.getNicno() %>  </td>
         <td style="background-color:ivory" noWrap width="174">
              <input type="text" name="<%= "basicSal" + iCounter %>" size="10"> </td>
    </tr>
    <%
    %>
    Date of interview<input type="text" name="date" size="17"></td>
    <input type="submit" value="APPROVE CANDIDATE" name="B1" style="border: 1px solid #0000FF">
    </form>........................................................
    Here is the error generated by TOMCAT.
    root cause
    java.lang.NullPointerException
         at org.apache.jsp.AddNewFinal_jsp._jspService(AddNewFinal_jsp.java:70)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
    I have goto the file "AddNewFinal_jsp.java". The line 70 points to the following line.
    for(int i=0; i < value.length; i++){ [/b]
    Please can someone help me to solve this problem? Please help me to do this task.
    Thanks.

    Hi Casabianca ,
    It is clearly that your problem is not on the database end, more like a servlet/jsp issue.
    I will not comment on the javascript portion, but rather the 2 jsps.
    a simple way to trace what's go wrong is to check the final result (the html code) of the first jsp (showFinal.jsp), and compare against what is expected by the 2nd jsp (AddNewFinal.jsp). Most browser do provide "view source" on the page visited.
    the following code
    <input type="checkbox" name="<%= "ChkNicno" + iCounter %>" value="<%=s.getNicno() %>">
    <input type="text" name="<%= "basicSal" + iCounter %>"
    would likely to be "translated" to html code something as follow:
    <input type="checkbox" name=""ChkNicno0" value="nicNo>">
    <input type="text" name="basicSal0">
    the original code in "AddNewFinal.jsp" using
    request.getParameterValues("ChkNicno");
    which looking for a none exist http request parameter (sent as "ChkNicno0",etc but look for "ChkNicno"), which has explained before.
    the second attempt to use String[] value = request.getParameterValues("ChkNicno" + iCounter); give Cannot resolove symbol :iCounter. because iCounter never defined in the 2nd jsp!
    Most of the error message do give clue to cause of error... : )
    not too sure on your intension, assume you wish to update only those selected (checked) row to db.
    some suggestions:
    1) <input type="text" name="ChkNicno" size="10"> </td>...
    <input type="text" name="basicSal" size="10"> instead.
    then use javascript to based on checked element index (refer to javascript spec for more details), for those index not checked, clear off the correspond index "basicSal" field value.
    e.g. ChkNicno[1] is not checked, empty basicSal[1] value before submission.
    This will give us only selected rows values.
    2) retain the code
    String[] value = request.getParameterValues("ChkNicno");
    String[] bs = request.getParameterValues("basicSal");at 2nd jsp, as now the http request will pass parameters using "ChkNicno" and "basicSal".
    3) some change to the code for optimization
    for(int i=0; i < value.length; i++){
         String temp = value;     
         for(int x=0; x < bs.length; x++){
              String basic = bs[x];
              pstmt2 = connection.prepareStatement(sql2);
              pstmt2.setString(1, temp);
              pstmt2.setString(2, basic);
              int RowCount1= pstmt2.executeUpdate();
         pstmt1 = connection.prepareStatement(sql);
         pstmt1.setString(1, temp);
         pstmt1.setString(2, interviewDate);
         int RowCount= pstmt1.executeUpdate();
    to
    pstmt1 = connection.prepareStatement(sql);
    pstmt2 = connection.prepareStatement(sql2);
    for(int i=0; i < value.length; i++){
         String temp = value;     
         for(int x=0; x < bs.length; x++){
              String basic = bs[x];
              pstmt2.setString(1, temp);
              pstmt2.setString(2, basic);
              int RowCount1= pstmt2.executeUpdate();
         pstmt1.setString(1, temp);
         pstmt1.setString(2, interviewDate);
         int RowCount= pstmt1.executeUpdate();
    preparestatement created once should be sufficient as we do not change the sql statement throughout the loop.
    there are better solutions out there, this just some ideas and suggestions.Do try out if you wish.
    Hope it helps. : )

  • Multiselect problem Help please!!

    Hi all,
    I am currently using Application Express 3.1.2.00.02 I have developed an online questionnaire with a multiselect list for one of the questions. The problem i am having is that i need each choice to be totaled up separately on the report generated.
    My table of answers looks like this:
    Column name e.g. (Question 9)
    Answer "Dog" "Cat" "Mouse" "Snake" (underneath column name Question 9 depending on what is selected).
    The reporting page would look like below:
    *(Column Question 9)* Count
    Dog 1
    Mouse 1
    Snake 1
    and for the question you could have another respondent who chooses similar of items on the multiselect, so their answer looks like this:
    Answer
    "Question 9" Dog
    "Question 9" Snake
    This would then start a new row on the reporting page like below which is not what i want:
    *(Column Question 9)* Count
    Dog 1
    Mouse 1
    Snake 1
    Dog: Snake 1
    But the report should look like this:
    *(Column Question 9)* Count
    Dog 2
    Mouse 1
    Snake 2
    The current SQLquery i am using is below:
    select "QUESTION 9",
    count(*) c
    from "P1 DQUESTIONNAIRE"
    group by "QUESTION 9"
    Thanks for your help and suggestions,
    'S'

    How to make sure your forum post will never be answered:
    1) Make sure your subject line is completely meaningless (i.e. HELP PLEASE!) and describes no part of your actual problem
    2) State that you are having "a few problems" but make sure to offer no details whatsoever what those problems are or what the symptoms are.
    3) Post large volumes of code instead of distilling the problem down to a compact snippet
    4) For extra points, make the code hard to read by refusing to make use of the "code" tag.

  • K8N Neo2-fx Ram problem Help please

    I have three ram(2x512MB single sided , 1x1GB double sided). Is there any way I can put them all on the motherboard? When I place them all the computer is not starting and it`s making a "beep" every 2-3 seconds. If i connect the 1GB double sided on the Dimm1(green) and the one 512MB single sided on the Dimm3(green) it`s working properly. Is there any way I can use all my ram at the same time. I`m desperate. Help please...  thank you

    Quote from: wodahS on 09-November-06, 05:55:17
    How can I put my computer facts under any post I am posting? I should make it my signature?
    That's the rule mate which you need to gives all your component in details including your PSU and Bios revision so that others can help you! Like what BOSSKILLER say it won't works with 3 DIMMS unless you purhased another 1 GB of RAM then it can solve your problem with 4 DIMMS or else with 2*512MB RAM. Make sure that you've lowered your HT to <=800Mhz as default is 1000Mhz. GD luck.

  • ICloud problems help please!

    I have an iPhone 6 and during the setup I must have did something wrong and now I have my old iCloud account on it that I no longer remember the password, security questions, and no longer have the email address to that account.  I think I was hacked and my password and security questions changed. I want to log out of iCloud and start using my current iCloud account.  I know these are security measures, but how can I get logged out??? My iPhone is having problems since the latest update and now I can't make a call or text.  I can't call apple support without a working number  HELP Please.

    Hello shelbyrecords,
    Oh no! That sounds really frustrating. Unfortunately, if iCloud Find my iPhone Activation Lock is enabled on the device we’ll need to gain access to your previous Apple ID account to disable it. Based on the information you have provided, it sounds like you may need a personalized support experience to recover your previous Apple ID:
    If you forgot your Apple ID password - Apple Support
    http://support.apple.com/en-us/HT201487
    Make sure that you’re entering the correct Apple ID. In most cases, your Apple ID is also the primary email address of your Apple ID account. If these steps didn't help you change your password, contact Apple Support.
    Thanks,
    Matt M.

  • Cropping in Elements 11 - Floating in Video Problem - Help Please!

    Please help - bottom of video looks like I am floating. Any help would be greatly appeciated.

    realjeffl
    From my point of view, I believe I know what you did, and I need no screenshot, unless you cannot confirm the following results.
    I am essentially certain that I fully understand what you did. It was your use of the Crop Tool and its settings that needs fine tuning.
    If you want to crop out that curtain from the left side of the Green Screen Clip, then please try this and let us know the results.
    a. Drag the Crop Effect into your Green Screen Clip on Video 1, either into the Monitor or the clip on the Timeline (Expert view) Video 1.
    b. Make sure the clip is selected, go to the Applied Effects Palette and the Crop Panel there. Expand the Crop Panel so that you see the settings options.
    There are Left, Top, Right, and Bottom sliders there. I cannot give you exact number for your specific situation, but follow this scheme:
    Left Slider,  move in direction to cut out your curtain on the left side of the Green Screen Image.
    Top Slider, move in direction to bring image to the top of the frame just until there is no black showing at the top.
    Right Slider, move in direction to bring image to the right edge of the frame until there is not black showing at the right side
    Bottom Slider, move in direction to bring image just to the bottom of the frame until there is no black showing at the bottom.
    Place a check mark next to Zoom. The frame should be filled with no black border and your person image should be seen intact.
    Go back to the Timeline and apply the Green Screen Key Effect to your clip.
    I have just done a run through to YouTube with this workflow. Please compare my first upload to YouTube (no cropping) with the current upload that incorporated cropping to get the curtain (seen in the first upload) cut out of the picture.
    http://www.youtube.com/watch?v=eGZHkJnEscY
    We will be watching for your comments.
    Thanks.
    ATR

  • Macbook stuck on white screen with apple logo. help please

    I have a macbook (black model) and while I was surfing on internet it is frozen. so I shut it down and restarted. When I restarted, it stuck on white screen with gray apple logo and seems like booting but nothing happens.
    after that, I restarted again and put installation disc (leopard) without pressing any key and it opened normally. I backed up os with time machine but in one hour it is frozen again.
    restarted again but this time it did not boot normally. so i tried booting from cd with c key, it opened installation screen. I have opened disk utility top repair disk, but when I click on disc image, repair / verify disk buttons are unavailable to click and S.M.A.R.T status is not supported.
    After all, I tried to erase and install system several times, but after language section when I click agree to terms and conditions, mac freeze again.
    So, I do not know what to do. Any help please?
    Note: I already tried PRM and Safe Mode. (after safe mode it took me to installation screen again and nothing changed.)
    Any help would be much appreciated!
    Uptade: Also, opened system profiler and clicked on Serial-ATA, it seems loading but do not show any info. stucked again! help please
    Message was edited by: burakbey

    HI,
    *"I have opened disk utility top repair disk, but when I click on disc image, repair / verify disk buttons are unavailable to click and S.M.A.R.T status is not supported."*
    You need to select "MacintoshHD 10.5.8 not "disc image" in order to run Disk Utility and Verify and if necessary, Repair the disk.
    That's why you are seeing this dialog.
    *are unavailable to click and S.M.A.R.T status is not supported.*
    Also, run the Apple Hardware Test.
    http://abclocal.go.com/kgo/video?id=7011117
    Carolyn

  • I can't find most of my files for the songs in my iTunes library and so cannot Sync them with my iPhone, Help please

    Help please! When I try to sync my iPhone it tells me it can't find most of my files for the songs in my iTunes library, although the songs are there!!

    Can anyone help?

  • I am struggling to know how to download music on to mp3. am useless with computers. simple help please !

    am really struggling to transfer music to mp3. not a clue how its done. Help please!

    You do not download music from iTunes as an MP3, all music is downloaded as an AAC file.
    iTunes 11 for Windows: Save a copy of a song in a new format

Maybe you are looking for

  • My iPad air's screen is broken, can I get a replacement free?

    It's in warrant.

  • Images in PDF reports

    I have a report that indicates the health of a project by showing an image, like a stop light. The query looks like this: select     "PM_PROJECTS"."ID" as "ID", '<img src="#APP_IMAGES#'||lower(HEALTH)||'.gif">' health_image,      "PM_PROJECTS"."OWNIN

  • Newbie needs Help!  How can I protect PART of a form in LiveCycle?

    I have an interactive form that will be completed in 2 stages. The first stage is completed by the Manager.  I can do a password protect to open in Adobe reader, they could input data into 4 fields and then save the document under a customer name.  S

  • Bad files out of QuickTime Broadcaster

    I am using QuickTime Broadcaster (1.5.3, running on Mac OS X Server 10.6.8) to stream a monthly sales meeting to our employees. The stream is also saved for later viewing. It's this saved stream I'm having issues with. The resulting QuickTime files a

  • XML Assembly Message Issue

    Hello, I'm sending the following Assembly XML message which is accepted and confirmed by the system (SAP ME 5.2. SP5). But the As-Built report is not showing anything assembled to the SFC. Request: <?xml version="1.0"?> <PRODUCTION_REQUEST xmlns:xsi=