Output even number between 1 and 50 without using any operator and extra variable. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Output even number between 1 and 50 without using any operator and extra variable.

first question.

20th Jun 2017, 7:18 PM
Hna
2 Answers
0
import java.util.concurrent.ThreadLocalRandom; public class Program { public static void main(String[] args) { // get a random number from 0 to 25 int x = ThreadLocalRandom.current().nextInt(0, 26); // use bitwise multiplication x*2 System.out.println(x<<1); } } if you want to get rid of the variable just move the line where x is and surround it in parentheses. (ThreadLocalRandom.current().nextInt(0, 26))<<1
20th Jun 2017, 8:28 PM
ChaoticDawg
ChaoticDawg - avatar
0
please use any operator at all (even bitwise multiplication)
22nd Jun 2017, 6:44 AM
Hna