Dasar-dasar Pemrograman : Latihan Soal Pemrograman beserta Jawabannya
Branching
Telephone
Your cell phone rings. Return true if you should answer it. Normally you answer, except in the morning you only answer if it is your mom calling. In all cases, if you are asleep, you do not answer.
B is OK
Given three ints, a b c, return true if b is greater than a, and c is greater than b. However, with the exception that if "bOk" is true, b does not need to be greater than a.
Double Digit
Given two ints, each in the range 10..99, return true if there is a digit that appears in both numbers, such as the 2 in 12 and 23.
Remainders
Given two int values, return whichever value is larger. However if the two values have the same remainder when divided by 5, then return the smaller value. However, in all cases, if the two values are the same, return 0.
Alarm Clock
Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off".
Loops
Repetition
§Given a string and an int n, return a string made of n repetitions of the last n characters of the string. You may assume that n is between 0 and the length of the string, inclusive.
Cat Dog
Return true if the string "cat" and "dog" appear the same number of times in the given string.
Sandwich
A sandwich is two pieces of bread with something in between. Return the string that is between the first and last appearance of "bread" in the given string, or return the empty string "" if there are not two pieces of bread.
Sumber
Soal Latihan UTS Daspro
EmoticonEmoticon