|
-
September 6th, 2009, 02:41 AM
#1
Sentinel-controlled loop
Hi how can i use a sentinel controlled loop to keep prompting the user to enter the next character after it computes whether the char is a digit or a vowel till the user inputs a sentinel character '#' it will exit the program.
import java.util.Scanner;
class test1 {
public static void main(String[] args) {
Scanner zz= new Scanner(System.in);
System.out.println("Enter a character:");
String s = zz.next();
char input = s.charAt(0);
if (input=='a'||input=='e'||input=='i'||input=='o'||input=='u') {
System.out.println("Vowel");
}
else if(Character.isDigit(input))
{
System.out.println("Digit");
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|