Hello all.
I have am currently working on a assignemtn and i am having trouble with calculating the prime number, which the user can enter. I am also having trouble with returing to the begining of the code if the user does not select one of the options available to them.
I am new to Java and wouldlove your help.
I have attached the code completed so far, any assistance you can provide would be great.
import java.io.*;
import java.util.*;
import java.lang.*;
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));
// This section declears the variables used in the program
String menuselection, voweltext;
// This section the the menu section that allows you to select your options
System.out.println("*****************Assignment 1 Menu*****************");
System.out.println("A. Check to see if a number is Prime.");
System.out.println("B. Count the number of Vowels in a line.");
System.out.println("X. Exit the program.");
System.out.println("***************************************************");
System.out.print("Please select one of the above options: ");
menuselection = selection.next();
//This section calculates if the number you entered is a prime number
if (menuselection.equalsIgnoreCase("A"))
{
//System.out.println("A selected");
System.out.println("Enter number:");
int num = Integer.parseInt(bf.readLine());
System.out.println("Prime number: ");
for (i=1; i < num; i++ )
{
int prime;
for (prime=2; prime<i; prime++)
{
int n = i%prime;
if (n==0)
{
break;
}
}
if(i == prime)
{
System.out.print(" "+i);
}
}
//This section calculates the amount of vowles within a text string.
else if (menuselection.equalsIgnoreCase("B"))
{
System.out.println("Please enter a line of text: ");
voweltext = selection.next();
int vowelCount = 0;
for (int i = 0; i < voweltext.length(); i++)
{
char currentChar = voweltext.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);
}
//This section exits the program
else if (menuselection.equalsIgnoreCase("X"))
{
System.out.println("Existing program goodbye...");
System.exit(0);
}
else if (menuselection != ("X"))
{
System.out.println("Error! invalid Selection");
}
}
}