switch case with integers and strings...
Hi, I'm new here on these forums, and fairly new to Java. In my programming class at University, we are asked for our assignment to:
"Write a Java application that prompts the user for an integer. Once the integer is received, use a switch statement to create a String variable to contain the number received followed by the appropriate suffix: st , nd , rd , or th . Note that there is a single space character after each of the suffixes.
For example, if the integer: 3 is entered, the string variable will contain: 3rd . If the integer: 97 is entered, the string variable will contain: 97th . The space character after the suffix has been added so that you can use the String variable in a sentence without having to worry about adding a trailing space character. Finally generate the following output: The value entered was: <integer value entered> Which has been converted to: <String variable created> (Note the: )
Once you have this program working, add the looping construct of your choice to continuously prompt the user to enter an integer for which you will generate the above output. To exit the program, the user must enter a
negative number (you may want to indicate this in a prompt somewhere).
Remember to test your program. Your program must be able to handle all of the positive integer values between0 and 1,000."
Sorry this is so long, but this is what i have so far:
public class Assign5d
public static void main (String  args)
Scanner keyboard = new Scanner(System.in);
int input, stringLength, lastNumberIndex;
System.out.println("Please enter a whole integer: ");
input = keyboard.nextInt();
UserNumber = "" + input;
stringLength = UserNumber.length(); //trying to get length of String to maybe help get the last number
of the string with the number in it
lastNumberIndex = UserNumber.lastIndexOf(input); //another method to try and get the last index
System.out.println(stringLength + " " + lastNumberIndex); //for testing purposes
I really dont know where to go from here...but I would appreciate if someone could just give me a push in the right direction (not the full answer) so that I can learn. no one in my class knows what they are doing and i quite possibly have the worst programming teacher ever. Thanks for any help!