Giter Club home page Giter Club logo

hw_week1_day4_functionsandstrings's Introduction

HW_week1_Day4_FunctionsAndStrings

Note: You must save your solution as solution_part1.kt for Part I, and solution_part2.kt for Part II to be submitted before 9AM. โš ๏ธ

Instructions ๐Ÿ“‹


Part I - Practice with functions and strings.


a. Write a function to display the middle character of a string.

fun main() {
   println(mdChar("ali"))
}

Output:

The middle character in the string: 5

b. Write a function to count all vowels in a string.

fun main() {
   println(vowCount("supermarket"))
}

Output:

Number of  Vowels in the string: 4

c. Write a function named isEven that accepts an int argument. The method should return true if the argument is even, or false otherwise.

fun main() {
    println(isEven(2))
}

Output:

true

d. Write a function named removeSpace() which removes spaces from a string

fun main() {
    println("John Doe)
}

Output:

JohnDoe

e. Write a function returns a new string with first and last character removed

Part III - Challenges (Optional).


a. Write a method that takes as input a string and returns true if the string is a palindrome;

    isPalindrome("radar")

Output:

    "radar" is a palindrome string.

b. Write a function to check whether a string is a valid password.

Password rules: A password must have at least ten characters. A password consists of only letters and digits. A password must contain at least two digits.

    validate("abcd1234")

Output:

    Password is valid: abcd1234 

c. Write a function named roundOff() which returns formated rounded float #.##

    roundOff(34.5458738f)

Output:

    34.50

Learning Resources ๐Ÿ“š

hw_week1_day4_functionsandstrings's People

Contributors

aalherz avatar sampaddock avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.