Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Week4: Solving the salesman problem, Working with strings Due: 2/12/2015 12:00:0

ID: 640223 • Letter: W

Question


Week4: Solving the salesman problem, Working with strings Due: 2/12/2015 12:00:00 AM Allow Late Submission Available at: 2/4/2015 12:00:00 AM Duration Description Solving the salesman probelm Introduction to strings Introduction to String class and String Buffer class. Checking palindrome for a string Validating password. Assignment: Refer to the attached programs in rar file and acheive the following. 1) Read a password and Validate with these test cases. No numbers and, atleast one special character and atleast 5 letters. 2) Read a string and check if the string has any vowels (a,e.i.o,u) using charAto function. If any vowels found, print them. Let me know any challenges. Deliverables A doc with output screenshot and .java file (code). Available Files: 4Programs.rar q

Explanation / Answer

import java.util.Scanner;

//main class
public class VowelsDemo
{

    public static void main(String[] args)
    {

    String str;
    int count =0;
  
        Scanner scn = new Scanner(System.in);
        System.out.print("Enter a String: ");
        str = scn.nextLine();
   
        for(int i = 0; i < str.length(); i++)
        {
            if(str.charAt(i) == 'a' || str.charAt(i) == 'A')
            {
                count++;
             
            }
            else if(str.charAt(i) == 'e' || str.charAt(i) == 'E')
            {
                count++;
            }
            else if(str.charAt(i) == 'i' || str.charAt(i) == 'I')
            {
                count++;
            }
            else if(str.charAt(i) == 'o' || str.charAt(i) == 'O')
            {
                count++;
            }
            else if(str.charAt(i) == 'u' || str.charAt(i) == 'U')
            {
                count++;
            }
        }
        System.out.println("Number of vowels: " + count);
       
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote