Hello Community,
I don't know if this some type of algorithm or just a method that I can use. Below is my code.
import java.util.*; public class algorithmTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print( " Please input a String value: "); String inputString = scan.nextLine(); System.out.print( " Please input a int value 1-25: "); int inputInt = scan.nextInt(); char[] myChar; myChar = inputString.toCharArray(); char myCharJr = myChar[0]; int intCharValue = (int)myCharJr; if( intCharValue >= 65 || intCharValue <= 90) { int charNew = inputInt + intCharValue; System.out.println( " New char value: " + (char)charNew); } else if( intCharValue >= 97 || intCharValue <= 122) { int charNew = inputInt + intCharValue; System.out.println( " New char value: " + (char)charNew); } else { System.out.println( "You value is greater than or less than the paramater" ); } } }
I'm doing an assignment and testing out a few things from this little test code. What I want to do is add the value of my char value and convert it into a integer. From converting it into a integer I want to shift the value depending on the users input i.e. an integer 1-26. Here is the problem I only want to display the alphabet A-Z and a-z. When I get to z or Z my program does what its supposed to do. Add the value. But I want it to start over i.e. User enters W..... user enters 6.... 6 is added to the ASCII value of 87((W) + 6). I want my ASCII value to start from A once it reaches to 90....and starts back to 65. Is there a way to do this. I hope this clarify my question.