In: Computer Science
1. Read a line of input from the user (as a string) and find out if there are any vowels in the string. Use a break or continue keyword (whichever is appropriate) to notify that a vowel has been found. Prompt for another string and search again until the user enters 'exit' into the program.
2. Ask the user how many random numbers they would like to see. Ask the user to provide the lowest number they would like to use and the highest number. Only return integers between those two numbers.
Java language
1)Java program:
import java.util.Scanner;
public class VowelFinder {
public static void main(String[] arg) {
//Scanner class object to read
input from keyboard
Scanner in = new
Scanner(System.in);
//asking user input
System.out.print("Enter
string:");
String line = in.nextLine();
//converting user input into
lowercase
line = line.toLowerCase();
//while loop till user enters
'exit'
while(!line.equalsIgnoreCase("exit")) {
//for loop to
traverse on the line
for(int i = 0; i
< line.length(); ++i)
{
//getting each character from the line
char ch = line.charAt(i);
//condition to check char is vowel or not
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' ||
ch == 'u') {
System.out.println("Vowel has been found");
break;//Use a break
}
}
//Prompt for
another string
System.out.print("Enter string:");
line =
in.nextLine();
}
}
}
Output:
2)Java program:
import java.util.Random;
import java.util.Scanner;
public class RandomNumGenerator {
public static void main(String[] arg) {
//Random number instance to
generate random numbers
Random r = new Random();
//Scanner class object to read
input from keyboard
Scanner in = new
Scanner(System.in);
//asking user input
System.out.print("How many random
numbers would you like to see?:");
int numOfRandomNums =
in.nextInt();
System.out.print("Provide the
lowest number would you like to use:");
int lowestNum = in.nextInt();
System.out.print("Provide the
highest number would you like to use:");
int highestNum =
in.nextInt();
//for loop to generate
'numOfRandomNums' random numbers
for(int
i=1;i<=numOfRandomNums;i++) {
// Generating
random integers from lowestNum to highestNum
int randomNum =
r.nextInt((highestNum - lowestNum) + 1) + lowestNum;
System.out.println(randomNum);
}
}
}
Output: