Java training #2

The Purpose of this training is to get familiar with:

  • Strings and some of their methods and behaviors
  • Basic work with Arrays
  1. Get a sentence as an input from the user and print to the screen each word of the sentence in a different line

  2. Get a sentence as an input and print the reversed sentence.
    Example:
    Input: hello world
    Output: world hello

  3. Get a sentence as an input and print to the screen:
        The number of words in the sentence
        The number of times that the letter ‘a’ appears,
        The number of times that the letter ‘f’ exists
        The number of commas in the sentence

  4. Get a sentence as an input and a number as an input. and do the following
    Example 1:
    Input: Hello world 3
    Output:
     hel
     lo
    wor
    ld

    Example 2:
    Input: taltaltal 3
    Output:
    tal
    tal
    tal

Note: In the examples above, the number 3 means => 3 letters will be print each time. space can be considered as letter  character.

Java training #1

The Purpose of this training is to get familiar with:

  • Numbers and simple calculations
  • For loops
  • If statements
  • Switch case statements
  • Reading input from the user (console) and writing output back to the screen

  1. Create a program that gets a number as an input from the user and calculates the sum of all the numbers from 1 till the input number.

  2. Create a program that gets 2 numbers as an input from the user and a string as an action (“add”, “subtract”, “multiply”, “divide”) and prints the outcome of the relevant action.
  3. Create a program that gets a number as an input from the user and prints to the screen the factorial of the number, and weather this number is primary or not.

Note: These are calculation exercises – no need for fancy classes and objects– We’ll get to that later.