hi chaps,I am very new to
java and I am reading the deitel and deitel book "java how to program" I would like to do this exercise taken from it, chapter 4 exercise 4.38, in brief: "Write an application that reads a 4 digit int and encrypt it replacing each digit with the result of addin 7 to it and getting the reminder after dividing the new value by 10. Then swap the first digit with the 3rd and swap the second with the fourt, then print the encrypted digit".
Now bearing in mind that I am only allowed to use a while statement (no for loops, no array, no switch and assuming the user enters numbers and not letters) because I haven't done them as yet, this is what I came up with so far, but I got somewhat stuck:
and
So basically I got to the point of reading the int in and encrypt it half way. What I am not entirely sure how to do, is to swap the digits according to the exercise. This becasue as you can see I am encrypting the int digit one by one. the function
returns the number to
but ideally I should return the number to
public void insertNumber(){
in order to be able to swap the digits (that by now are part of a
string). However I am not able to return //return fullNumber; even if I make the due changes because the compiler tells me that the variable hasn't been initialize. ANyway, has anybody got any suggestion please?
thanks