Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

I'm trying to print multiple random numbers for a give time using lettertest(num) I also need to return the number to set a new value for a old numer. How? public static int timewait(int times){ // print Rand number int num; for(int i=0; i

OpenStudy (anonymous):

What programming language is that ?

OpenStudy (anonymous):

probably java, I haven't learnt about threads and catching exceptions yet, so not sure what try {...} does

OpenStudy (anonymous):

@Tomas Basically, the code inside the try {} block is executed, but whenever an exception (in this case, the program is specifically expecting an InterruptedException) occurs within that block the catch {} block right after it will handle it, and therefore control will be transferred to the part inside the except {} block, instead of just having the entire program crash :-D

OpenStudy (anonymous):

oops I meant the catch {} block in the last part of my explanation (I get confused since except is the keyword used in Python's try-except clauses)

OpenStudy (anonymous):

anyway in this piece of code the try-except clause is just used so that the whole program doesn't crash in case something weird happens when calling Thread.sleep

OpenStudy (anonymous):

so when exception comes it does nothing and just continues program?

OpenStudy (anonymous):

yeah, notice the empty braces after the except()

OpenStudy (anonymous):

oops I meant catch() :-P

OpenStudy (anonymous):

it will always return 1 number or it won't work at all because I don't know such method Rand and I don't have idea what lettertest does

OpenStudy (anonymous):

IS IT JAVA ?

OpenStudy (anonymous):

It is definitely some kind of Java.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!