Question

In: Computer Science

1. Read a line of input from the user (as a string) and find out if...

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

Solutions

Expert Solution

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:


Related Solutions

Create a class that calls for user to input a string. Pass the string from that...
Create a class that calls for user to input a string. Pass the string from that class to another and count how many words the string has, count how many vowels are in the string and count how many letters end with d. java language
Read three integers from user input.
Read three integers from user input.
In Python Write a function to read a Sudoku board from an input string. The input...
In Python Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5 385...
The user will input a dollar amount as a floating point number; read it from input...
The user will input a dollar amount as a floating point number; read it from input using a Scanner and the .nextDouble() method. Convert the number of dollars into a number of whole (integer) cents, e.g., $1.29 = 129 cents. Determine and output the optimal number of quarters, dimes, nickels, and pennies used to make that number of cents. Ex: if the input is 1.18 The output should be 4 1 1 3 for 4 quarters, 1 dime, 1 nickel,...
C++ Text message decoder Use getline() to get a line of user input into a string:...
C++ Text message decoder Use getline() to get a line of user input into a string: Enter text: IDK if I'll go. It's my BFF's birthday. Search the string using find() for common abbreviations and replace() them with their long form. In addition, use a for loop to iterate through each character of the string and replace any occurences of '.' with '!': Enter text: IDK if I'll go. It's my BFF's birthday. I don't know if I'll go! It's...
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
Write a program that will read user input, and do the following: 1. The user can...
Write a program that will read user input, and do the following: 1. The user can input letters [A-Z] as much as he wants (ignore case). 2. If the user input other than letters or two characters, stop the input process and start to print unduplicated sorted pairs such as the below examples: User input: A a e b d d D E a B 1 Output: AB AD AE BD BE DE User Input: a q w e dd...
Write a program that read the input from user and convert it to binary and hex...
Write a program that read the input from user and convert it to binary and hex in C language.
Write a program that gathers input from the user and writes the information out to a...
Write a program that gathers input from the user and writes the information out to a file (output.txt).   Your main method should gather the input, calculate the average, and write the output. You should have a separate method that writes the output to a file. You can have other methods as well if you choose. However, you MUST have at least one other method in addition to the main method. Inputs: Student Number Name Class name Grades 1-5 (5 individual...
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT