Comprehension - To and Until

Write a code to print numbers from 1 to (input) using to , and print numbers in range 1 to input using until .

Copy the following ForComprehensions1 program into the file: `object ForComprehensions1 extends App {
val input : Int = args(0).toInt
//complete the code
println()
//complete the code
}

Expected Output :

Output will be:
123
12

Below is my code

object ForComprehensions1 extends App {
val input : Int = args(0).toInt
for (i <- 1 to 3) {
println(i)
}
for (i <- 1 until 3)
println(i)
}
}

Though i get output , unable to proceed!
Capture|690x199

Just use print instead of println.

HI … Thanks for your response.
Though i get the output … not able to proceed

Can you contact some teacher or teacher assistant or administrator of the site?
You have the correct output, but it seems that the system wants the output in a different format. There is not much that we can do about that.

Is it because … im trying println() after the response
object ForComprehensions1 extends App {
val input : Int = args(0).toInt
for (i <- 1 to 3) {
print(i)
}
println()
for (i <- 1 until 3)
print(i)
println
}
}

If i dont use println() at the last my response is with $ at the end
123
12$

1 Like

Your code is wrong.

It might be. Without examining the system that wants your output we cannot tell. The print(s) call prints the string without a newline. println(s) prints the string with a newline (or without an argument just a newline).

Personally I would have expected

for (i <- 1 to 3) {
  print(i)
}
println()

for (i <- 1 until 3) {
  print(i)
}
println()

to make sure you have a newline after each sequence of results.

1 Like