"detection" by checking for possible cycles or knots.
Answer:
Explanation:
The following code is written in Java. It asks the user for an input and saves it in a String variable. Then it loops through all the characters in the string and counts the spaces. Finally, it prints the total number of spaces in the String.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter Line Now:");
String userInput = in.nextLine();
int spaceCount = 0;
for (int x = 0; x < userInput.length(); x++) {
if (userInput.charAt(x) == ' ') {
spaceCount++;
}
}
System.out.println(spaceCount);
}
Answer:
Explanation:
Let's do this in Python. We will loop through 4 times, each of the loop would compute the dividend, store it as string in a result variable and finally print the result on the same line:
def divide_4_times(user_num, x):
result = ''
for i in range(4):
user_num /= x
result += (' ' + str(user_num))
print(result)