0
Output even number between 1 and 50 without using any operator and extra variable.
first question.
2 ответов
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
0
please use any operator at all (even bitwise multiplication)