STIN3084-A192-GENETIC-ALGORITHM / EXERCISE

0 stars 0 forks source link

EXERCISE #1

Open Jayyijianyi opened 4 years ago

Jayyijianyi commented 4 years ago

Submission SGA.java

azmanyasin commented 4 years ago

INSTRUCTION:

  1. Fill in the blanks in the program below as follows: (a) declare the variable town as a reference to a String object and initialize it to " UUM Sintok". (b) write an assignment statement that invokes the length method of the String class to find the length of the college String object and assigns the result to the stringLength variable (c) complete the assignment statement so that change1 contains the same characters as college but all in upper case (d) complete the assignment statement so that change2 is the same as change1 except all capital O's are replaced with the asterisk (*) character. (e) complete the assignment statement so that change3 is the concatenation of college and town (use the concat method of the String class rather than the + operator)

// ** // StringExercise.java // // Play with String objects // ** public class StringExercise { public static void main (String[] args) { String college = new String ("College of Arts and Sciences"); ____; // part (a) int stringLength; String change1, change2, change3; ____; // part (b) System.out.println (college + " contains " + stringLength + " characters."); change1 = __; // part (c) System.out.println ("The string is all in upper case: " + change1); change2 = __; // part (d) System.out.println ("All capital O's are replaced with the asterisk character: " + change2); change3 = __; // part (e) System.out.println ("The final string is " + change3); } }

  1. Write a program called “FunnyString” that asks the user to enter a favourite color, food, animal and the first name of a friend. Use a Scanner object and read one thing per line. The program should than print the following: For example if the user entered blue for color, burger for food, cat for the animal and Jack for the friend the output will be:
    I had a dream that Jack ate a blue cat and said it tasted like burger !

  2. Write a program that read a string for a date in the format day/month/year and displays it as in the format day.month.year. For example if the input is 13/09/18 the output should be 13.09.18 .

    Hint: Search in the class String for the appropriate method to solve this problem.

  3. Write a program that reads a four-digit number (such 2018) as a String and then display it one digit per line like so: 2 0 1 8

    (Use charAt() method from String, Think about the right type for the variables you use).

    Next, print the sum of the digits.
    Hint: Use Integer.parseInt() to convert digits to integers.

SUBMISSION

wilsonkhor1997 commented 4 years ago

https://github.com/wilsonkhor1997/Genetic-Algorithm

abraranuar commented 4 years ago

EXERCISE.docx

aizathakimi97 commented 4 years ago

EXERCISES GA SUBMISSION 1.docx