Can you convert a string like "Sunday" to the integer 0 in order to incerment to the next day or decrement to the previous day?
Printable View
Can you convert a string like "Sunday" to the integer 0 in order to incerment to the next day or decrement to the previous day?
put it in an array of Strings and then increment the index of the array. Use the mod operator (%) if you want to be able to loop through the array. For instance if you have an array of week days, you'd increment the index then mod it by 7 so that when you went past 6 (Saturday), you'd next hit 0 (Sunday).
public class ConvertStringToInt {
public static void main(String[] args) {
String aString = "78";
int aInt = Integer.parseInt(aString);
System.out.println(aInt);
}
}
raq, your post has nothing to do with the OP's question and contains spam advertisement in your signature which I've removed. Please consider yourself warned to cease and desist.
I did it for a few days, but then un-banned him as I saw that he/she posted something relatively helpful in another thread.
If you want to deal with days of a week (to keep set of constant) enum is much better.
Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects)