/
* Program Description: The program asks the user to choice from the menu an option
* A. Check to see if a number is prime.
* B. Count the number of vowels in a line.
* X. Exit the program.
*/
import java.io.*;
import java.util.*;
import java.lang.String;
public class Assignment_1
{
public static void main(String[] args)
throws IOException
{
Scanner selection = new Scanner(System.in);
BufferedReader stdin = new BufferedReader
(new InputStreamReader (System.in));
String menuSel, text;
for( ;; ){
// The menu section for the user to an option.
System.out.println("\n *******************Assignment 1 Menu*******************");
System.out.println("\t A. Check to see if a number is Prime");
System.out.println("\t B. Count the number of Vowels in a line.");
System.out.println("\t X. Exit the program.");
System.out.println("********************************************************\n");
System.out.print("Please select one of the above options (A, B or X): ");
menuSel = selection.next();
// calculates if the number you entered is a prime number
if (menuSel.equalsIgnoreCase("A"))
{
System.out.println("\n Please enter a Integar: ");
int num = Integer.parseInt(stdin.readLine());
if (num > 0 && (num % 2) != 0)
{
System.out.println("\n The number " +num+ " is prime.");
}
else if (num == 0)
{
System.out.println("\n Please enter a number larger than 0.");
}
else
System.out.println("\n The number " +num+ " is not prime");
}
// The section is to calculate the numbers of vowels in an inputed text.
else if (menuSel.equalsIgnoreCase("B"))
{
System.out.println("\n Please enter a line of text: ");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
text = bf.readLine();
int vowelCount = 0;
for (int i = 0; i < text.length(); i++)
{
char currentChar = text.charAt(i);
if (currentChar == 'A' || currentChar == 'a'
|| currentChar == 'E' || currentChar == 'e'
|| currentChar == 'I' || currentChar == 'i'
|| currentChar == 'O' || currentChar == 'o'
|| currentChar == 'U' || currentChar == 'u')
vowelCount++;
}
System.out.println("");
System.out.println("Number of vowels found in the line is " + vowelCount);
}
// The section terminates the program.
else if (menuSel.equalsIgnoreCase("X"))
{
System.out.println("Existing program goodbye...");
System.exit(0);
}
else if (menuSel != ("X"))
{
System.out.println("Error! invalid Selection");
}
} // End of the for loop
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
User_Menu_Choice.rar_The Count
共1个文件
txt:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 26 浏览量
2022-09-23
08:07:52
上传
评论
收藏 1KB RAR 举报
温馨提示
Program Description: The program asks the user to choice from the menu an option A. Check to see if a number is prime. B. Count the number of vowels in a line. X. Exit the program.
资源推荐
资源详情
资源评论
收起资源包目录
User_Menu_Choice.rar (1个子文件)
User_Menu_Choice.txt 4KB
共 1 条
- 1
资源评论
alvarocfc
- 粉丝: 131
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功