Necklace Problem Help
Hey guys, I'm a beginner programmer (so don't assume that I would know anything) and I'm having trouble with this necklace problem. Some of you probably know what it is, but I'll post it anyway:
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
Can anyone post the basic code for this, because I am just getting into iteration and this is all sort of confusing for me. I know what to do to solve the problem mathematically, but the variables are really tricky because you have to assign new values to existing variables. Also, I'm pretty sure a do-while loop will work here, but I do not know the specifics. Please, any help would be greatly appreciated.
Ok, sorry about that.
What I have is:
public class Necklace
public static void main(String[] args)
String output = "";
String first, second;
first = JOptionPane.showInputDialog ("Enter a single-digit number:");
second = JOptionPane.showInputDialog ("Enter another single-digit number:");
int f = Integer.parseInt (first);
int s = Integer.parseInt (second);
int sum = f + s;
int next = sum%10;
int previous = s;
while (previous != f && next !=s)
sum = next + previous;
previous = next;
next = sum%10;
output += (next + "");
JOptionPane.showMessageDialog (null, output, "Necklace", JOptionPane.PLAIN_MESSAGE);
I'm not sure where I'm off, but when I run it the output begins with 7 (the fourth term in the sequence) and ends with a 3 (the 10th term). I do not know how to get it to begin with the original two values that the user inputs, because those variables change, and I am not sure why it is not continuing to the end. Also, this is fairly minor, but is there a way to get the entire sequence to appear in one pop-up message dialog box, instead of the sequence gaining one value at a time after clicking OK? Thanks in advanced.
Similar Messages
-
My daughter has just bought me an iPad 2 from Dubai and set it all up for me but unfortunately the iMessage function doesn't seem to work. We keep getting messages,when trying to activate it, that there is a network connection problem - help!
Thank you both for your responses but my daughter was reassured by the salesman in the iStyle store (official Apple store in the UAE) that iMessages would work but conceded that FaceTime wouldn't. My iTunes account is registered in the uk and my daughter's iPhone has iMessages even though she bought it (and uses it) in Dubai. Can anyone else throw any light on this?
-
I couldn't log into my apple account on my iPad, then i couldn't unlock it resulting in it being disabled, however it's the same as my iPhones password, I then called apple, i was hung up on twice and they said it will cost £70 to fix THEIR problem, help?
If you cannot remember the passcode, you will need to restore your device using the computer with which you last synced it. This allows you to reset your passcode and resync the data from the device (or restore from a backup).
If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present.
You may have to force iPad/iPod into Recovery Mode
http://support.apple.com/kb/ht4097 -
IPad syncing problem - HELP!
iPad sync problem - HELP! I keep getting this message "...cannot be synced because there is not enough free space to hold all of the items in the iTunes library (additional ...space needed)" and yet I seem to have plenty of space on the iPad. This just started today. I even tried deleting some things to make even more room, but it didn't help. Any ideas???
I was thinking of restoring, but I've never done it... should I?
thank you!Hello florafromnv,
Welcome to Apple Support Communities.
The following article addresses how to resolve the issues related to this message:
iOS: "Not enough free space" alert when trying to sync
http://support.apple.com/kb/TS1503
Regards,
Jeff D. -
This topic has been moved to Overclockers & Modding Corner.
KT333 Ultra; fuzzy logic, 1.6xp overclocking problem help !!!!!Not that I am an expert o/c but here are some thoughts on the matter.
My comments are based on my experiences of the KT3 Ultra2 which is basically the same as the Ultra version.
This mobo does not have the ability to lock the PCI/AGP bus freely from the FSB. However, it does have dividers. At 133 a 1/4 divider kicks in. Above 152FSB the 1/5 divider works, so that at 166 the PCI & AGP buses will be back in sync. If you are o/c your cpu, don't go from 133 to 145, etc since you will be running the PCI/AGP buses further out of whack. Just go to either the mid 150's or to 166 in one jump. The other problem / issue relates to your cpu. From what you say you have one of the old Palominos which are not great o/c's. I would personally o/c your cpu from the BIOS rather than 'Fluffy Logic' which I would tend to stay away from.
With a 166FSB cpu a very stable o/c would be 175-177 beyond 180 gets decidedly tricky.
Hope this helps -
Help!! Itunes keeps closing straight away and message states 'windows has detected a problem' HELP ASAP PLEASE!!!!
For general advice see Troubleshooting issues with iTunes for Windows updates.
The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
If you've already tried a complete uninstall and reinstall try opening iTunes in safe mode (hold down CTRL+SHIFT as you start iTunes) then going to Edit > Preferences > Store and turning off Show iTunes in the Cloud purchases. You may find iTunes will now start normally.
tt2 -
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 9My 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. -
i have installed photoshop elements 12.
when I try use the editing features it said that i must login to Adobe to register the product.
but each time i try to it said there is a problem.
help
the problem stated that the internet is not connected, but that is not the case.I had the same issue and I'm running Windows 7. Tried working with technical support for several hours but they were no help. They just had me doing the same things over and over, offering no real answers. I finally got fed up and have decided to return my product for a full refund.
-
I can't install the itunes to my windows 7 X86 APPCRASH problem, help me guys
i can't install the itunes to my windows 7 X86 APPCRASH problem, help me guys?? i don't know what to do..
Why are you unable to install the iPod Updater? Are you getting an error message? Please be specific.
Cheers!
-Bryan -
Camera (focus) problem - help?
Duplicate post, please see: Camera (focus) problem - help?
Message was edited by: Admin ModeratorWarranty is valid only in country of original purchase. You have to return
the iPhone to the US for evaluation. Either you return it personally or send
it to a friend/relative/co-worker in the US to take into Apple. Apple will not
accept international shipments for evaluation nor will Apple ship out of the
country after repair/replacement.
Have you tried the standard trouble shooting steps: restart, restore, restore
as new iPhone? -
after update iPhone4 to iOS6, its stuck, showing only USB to iTunes on the screen. What to do, how to solve problem, help
Connect your phone to iTunes on your computer like the diagram has indicated and restore the phone
-
RFC Receiver adpater Connection problem , Help us to solve ?
Hi Friends ,
Our scenarilo is Mail to RFC. It was running fine. In RFC Receiver adapter i have given <b>Maximium connection property to 1</b> .
While multiple set data passed to rfc will connection problem will come ?
Most data not uploaded . I am getting the following error.
<b> If i set max connection to 5 . It is 5 times or more than that it is pusing the data .</b>
i am getting the following error <b>while i set the Max connection to 1 .</b> . <b>Any other place i need to change configuration ?</b>
<i><b> - Error: 2007-09-24 10:51:22 GMT-05:30: Message processed for interface YRFC_EXT_WARR: com.sap.aii.af.rfc.afcommunication.RfcAFWException: error while processing message to remote system:com.sap.aii.af.rfc.core.client.RfcClientException: resource error: could not get a client from JCO.Pool: com.sap.mw.jco.JCO$Exception: (106) JCO_ERROR_RESOURCE: Connection pool RfcClient[CC_EXTE_WAREN_2W_RFC_RECEIVER]e7fa21f86ec535e883636c0beffc0f0c is exhausted. The current pool size limit (max connections) is 1 connections.</b></i>
Please give the description . I have referred many likns . Help us to solve this problem .
Regards.,
V.Rangarajan<b></b>
Message was edited by:
ranga rajanHi,
Have a look at this.This will help you.
1.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f3f93ee7-0c01-0010-2593-d7c28b5377c2
2. https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3103eb90-0201-0010-71af-be6f4a6f61d1
Regards,
Akshay Jamgaonkar.
Reward points if find useful.
Message was edited by:
Akshay Jamgaonkar -
Table Control Text fields problem , help plz
Hello Anand , Rich , John & All
I hav problem with Text 3 fields( type c)(either L or R aligned ) , it is not geting updated , otherwise everything else is perfectly fine(scrolling,sorting etc ....) .
Fields giving problem are
1. Status(20) type c
2. Fdat type date
3. Remark(100) type c
All numerical fields are working fine .
<u><b> My yahoo messenger-id is [email protected]</b></u>
<b>Any light on this will be awarded plz .</b>
FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE SET_STATUS.
LOOP AT ITAB
WITH CONTROL TCL1
CURSOR TCL1-CURRENT_LINE .
MODULE SET_LINE_COUNT .
ENDLOOP.
PROCESS AFTER INPUT.
MODULE UPD_OK_COD.
MODULE EXIT_COMAND AT EXIT-COMMAND.
MODULE SCROLL_SORT.
LOOP AT ITAB.
MODULE UPDATE_ITAB.
ENDLOOP.
MODULE UPDATE_TABLE.
REPORT ZSD_REP_ORDER_BANK_CHANGE NO STANDARD PAGE HEADING LINE-SIZE 255.
TABLES: VBAK,VBAP,VBRK,ZSD_TABL_ORDBANK,MARA,KONV.
CONTROLS: TCL1 TYPE TABLEVIEW USING SCREEN 0200.
DATA: ITAB LIKE ZSD_TABL_ORDBANK OCCURS 0 WITH HEADER LINE,
WA_ITAB LIKE ZSD_TABL_ORDBANK,
OK_CODE LIKE SY-UCOMM,
SAVE_OK_CODE LIKE SY-UCOMM,
UPD_OK_CODE LIKE SY-UCOMM,
ANSWER TYPE C,
I LIKE SY-LOOPC ,
J LIKE SY-LOOPC,
V_LINES LIKE SY-LOOPC,
LINE_COUNT LIKE SY-LOOPC,
STS TYPE N,
EMGRP LIKE MARA-EXTWG,
QTY LIKE ZSD_TABL_ORDBANK-QTY,
UPRICE LIKE ZSD_TABL_ORDBANK-UPRICE,
TOT LIKE ZSD_TABL_ORDBANK-TOT,
INO LIKE VBAP-POSNR,
COL TYPE CXTAB_COLUMN,
COPIED_ONCE ,
FLDNAME(100),HELP(100).
FIELD-SYMBOLS:
<FS_ITAB> LIKE LINE OF ITAB,
<FS_TCL1> LIKE LINE OF TCL1-COLS.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS: S_CCODE FOR ZSD_TABL_ORDBANK-CCODE
NO INTERVALS NO-EXTENSION OBLIGATORY,
S_SORG FOR ZSD_TABL_ORDBANK-SORG
NO INTERVALS NO-EXTENSION OBLIGATORY,
S_DCHAN FOR ZSD_TABL_ORDBANK-DISTCHAN,
S_DIV FOR ZSD_TABL_ORDBANK-DIV,
S_MATNO FOR ZSD_TABL_ORDBANK-MATNO,
S_CUSTNO FOR ZSD_TABL_ORDBANK-CUSTNO ,
S_QTNO FOR ZSD_TABL_ORDBANK-QTNO,
S_QTDAT FOR ZSD_TABL_ORDBANK-QTDAT,
S_QTVDAT FOR ZSD_TABL_ORDBANK-QTVALDAT,
S_SONO FOR ZSD_TABL_ORDBANK-SONO.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN.
SELECT * FROM ZSD_TABL_ORDBANK
INTO TABLE ITAB
WHERE CCODE IN S_CCODE
AND SORG IN S_SORG
AND DISTCHAN IN S_DCHAN
AND DIV IN S_DIV
AND MATNO IN S_MATNO
AND CUSTNO IN S_CUSTNO
AND QTNO IN S_QTNO
AND QTDAT IN S_QTDAT
AND QTVALDAT IN S_QTVDAT
AND SONO IN S_SONO .
IF SY-SUBRC EQ 0.
REFRESH ITAB.
CLEAR COPIED_ONCE.
CALL SCREEN 0200.
ELSE.
MESSAGE E012(ZQOTBANK) .
ENDIF.
*& Module SET_STATUS OUTPUT
* text
MODULE SET_STATUS OUTPUT.
SET PF-STATUS '0200'.
SET TITLEBAR '0200'.
IF COPIED_ONCE IS INITIAL.
SELECT * FROM ZSD_TABL_ORDBANK
INTO TABLE ITAB
WHERE CCODE IN S_CCODE
AND SORG IN S_SORG
AND DISTCHAN IN S_DCHAN
AND DIV IN S_DIV
AND MATNO IN S_MATNO
AND CUSTNO IN S_CUSTNO
AND QTNO IN S_QTNO
AND QTDAT IN S_QTDAT
AND QTVALDAT IN S_QTVDAT
AND SONO IN S_SONO .
IF SY-SUBRC EQ 0.
DESCRIBE TABLE ITAB LINES V_LINES.
TCL1-LINES = V_LINES.
ENDIF.
COPIED_ONCE = 'X'.
REFRESH CONTROL 'TCL1' FROM SCREEN '0200'.
ENDIF.
LOOP AT ITAB.
QTY = ITAB-QTY.
UPRICE = ITAB-UPRICE.
TOT = QTY * UPRICE .
ITAB-TOT = TOT .
CLEAR: QTY, UPRICE, TOT.
QTY = ITAB-CGL_QTY.
UPRICE = ITAB-CGL_UPRICE.
TOT = QTY * UPRICE .
ITAB-CGL_TOT = TOT .
CLEAR: QTY, UPRICE, TOT.
QTY = ITAB-BHEL_QTY.
UPRICE = ITAB-BHEL_UPRICE.
TOT = QTY * UPRICE .
ITAB-BHEL_TOT = TOT .
CLEAR: QTY, UPRICE, TOT.
QTY = ITAB-ALSTOM_QTY.
UPRICE = ITAB-ALSTOM_UPRICE.
TOT = QTY * UPRICE .
ITAB-ALSTOM_TOT = TOT .
CLEAR: QTY, UPRICE, TOT.
QTY = ITAB-SIEMENS_QTY.
UPRICE = ITAB-SIEMENS_UPRICE.
TOT = QTY * UPRICE .
ITAB-SIEMENS_TOT = TOT .
CLEAR: QTY, UPRICE, TOT.
QTY = ITAB-TELK_QTY.
UPRICE = ITAB-TELK_UPRICE.
TOT = QTY * UPRICE .
ITAB-TELK_TOT = TOT .
CLEAR: QTY, UPRICE, TOT.
QTY = ITAB-OTH_QTY.
UPRICE = ITAB-OTH_UPRICE.
TOT = QTY * UPRICE .
ITAB-OTH_TOT = TOT .
CLEAR: QTY, UPRICE, TOT.
MODIFY ITAB.
ENDLOOP.
ENDMODULE. " SET_STATUS OUTPUT
*& Module SET_LINE_COUNT INPUT
* text
MODULE SET_LINE_COUNT OUTPUT.
LINE_COUNT = SY-LOOPC.
ENDMODULE. " SET_LINE_COUNT INPUT
*& Module UPD_OK_CODE INPUT
* text
MODULE UPD_OK_COD INPUT.
IF OK_CODE = 'SAVE'.
UPD_OK_CODE = OK_CODE.
* CLEAR OK_CODE.
ENDIF.
ENDMODULE. " UPD_OK_CODE INPUT
*& Module EXIT_COMAND INPUT
* text
MODULE EXIT_COMAND INPUT.
SAVE_OK_CODE = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK_CODE.
WHEN 'BACK'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = 'Order Bank Entry'
TEXT_QUESTION = 'Do you want to Go BacK ?'
TEXT_BUTTON_1 = 'Yes'
TEXT_BUTTON_2 = 'No'
DEFAULT_BUTTON = '2'
IMPORTING
ANSWER = ANSWER.
IF ANSWER = '1'.
LEAVE TO SCREEN 0.
ELSE.
ENDIF.
WHEN '%EX'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = 'Order Bank Entry'
TEXT_QUESTION = 'Do you want to Exit ?'
TEXT_BUTTON_1 = 'Yes'
TEXT_BUTTON_2 = 'No'
DEFAULT_BUTTON = '2'
IMPORTING
ANSWER = ANSWER.
IF ANSWER = '1'.
LEAVE TO SCREEN 0.
ELSE.
ENDIF.
ENDCASE.
ENDMODULE. " EXIT_COMAND INPUT
*& Module UPDATE_MOD INPUT
* text
MODULE UPDATE_ITAB INPUT.
MODIFY TABLE ITAB FROM ITAB.
ENDMODULE. " UPDATE_MOD INPUT
*& Module SCROLL INPUT
* text
MODULE SCROLL_SORT INPUT.
SAVE_OK_CODE = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK_CODE.
WHEN 'P--'.
TCL1-TOP_LINE = 1.
WHEN 'P-'.
TCL1-TOP_LINE = TCL1-TOP_LINE - LINE_COUNT.
IF TCL1-TOP_LINE LE 0.
TCL1-TOP_LINE = 1.
ENDIF.
WHEN 'P+'.
I = TCL1-TOP_LINE + LINE_COUNT.
J = TCL1-LINES - LINE_COUNT + 1.
IF J LE 0.
J = 1.
ENDIF.
IF I LE J.
TCL1-TOP_LINE = I.
ELSE.
TCL1-TOP_LINE = J.
ENDIF.
WHEN 'P++'.
TCL1-TOP_LINE = TCL1-LINES - LINE_COUNT + 1.
IF TCL1-TOP_LINE LE 0.
TCL1-TOP_LINE = 1.
ENDIF.
WHEN 'SORTUP'.
READ TABLE TCL1-COLS ASSIGNING <FS_TCL1> WITH KEY SELECTED = 'X'.
IF SY-SUBRC = 0.
SPLIT <FS_TCL1>-SCREEN-NAME AT '-' INTO HELP FLDNAME.
SORT ITAB ASCENDING BY (FLDNAME).
ENDIF.
WHEN 'SORTDN'.
READ TABLE TCL1-COLS ASSIGNING <FS_TCL1> WITH KEY SELECTED = 'X'.
IF SY-SUBRC = 0.
SPLIT <FS_TCL1>-SCREEN-NAME AT '-' INTO HELP FLDNAME.
SORT ITAB DESCENDING BY (FLDNAME).
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND INPUT
*& Module TABL_UPD INPUT
* text
MODULE UPDATE_TABLE INPUT.
CASE UPD_OK_CODE.
WHEN 'SAVE'.
UPDATE ZSD_TABL_ORDBANK FROM TABLE ITAB .
IF SY-SUBRC EQ 0.
MESSAGE I002(ZQOTBANK) .
CLEAR UPD_OK_CODE.
ELSE.
MESSAGE E003(ZQOTBANK) .
ENDIF.
ENDCASE.
ENDMODULE. " TABL_UPD INPUT
Thnx
moni<b></b><b></b>
Message was edited by: md monirujjaman
Message was edited by: md monirujjamanHi Moni,
The problem as I had replied in your earlier post is with the MODIFY statement.
MODIFY TABLE ITAB FROM ITAB. This statement will do the modifications based on the table key. When you have character fields as editable, then some problems are to be anticipated. In such a scenario, you must update the internal table based on the <i>index</i>, rather than based on <i>key</i>.
So consider using
MODIFY ITAB FROM ITAB INDEX TCL-CURRENT_LINE.
Where TCL is the name of the Table Control. Also observe the difference in syntax here, don't use the TABLE keyword for the MODIFY statement.
Please try it out and let me know.
Regards,
Anand Mandalika. -
Video Capture Problems HELP!
Ok i just bought a MSI GeForce4 Ti4200-VTD8X, Wich got Tv_Out + Video_in
With the card i got a Tv_out/Video_in connecter to plug in the card, now the problem seems to come, i plug my S-video cable behind my Tv_out/Video_in connecter (wich of course is connectet to my graphics adapter) and the other end of the S-video cable into a SCART Adapter wich i plug into the scart output on my VCR, but when i start any video capture software, it just says no device connectet plz HELP me! :(Never mind, got it working all by myself now
Maybe you are looking for
-
Cant download itunes, help?
i have a windows vista, and everytime i try to download iTunes it will start to download but will then freeze where it says publishing product information, any ideas?
-
CRM_ORDER_MAINTAIN not working as RFC
Hi , we need to change the msg partner for a support desk msg from webdynpro application.for that we are creating a custom RFC function module, Contains the below coding , CRM_ORDER_MAINTAIN CRM_ORDER_SAVE BAPI_TRANSACTION_COMMIT It is successfully
-
How to know whether the current database is using a password file or not?
How to know whether the current database is using a password file or not?
-
Tethering with Nikon D600 - no camera found!!!!
This is incredibly frustrating to have a $2,000+ camera that cannot connect to Lightroom. It really impacts the value of both Lightroom and my camera if they don't talk to each other. Please advise when you anticipate this being fixed in an update.
-
Just curious what everyone's thoughts are on the number of iPhone 6/Plus the Verizon retail stores will have?