I have used the Random class to generate a random number and the number shows up, but when I try to add that generated random number with 10 it just get concatenated i.e if the random number is 20 it will show as 2010
import java.util.Random;
public class MainClass{
static int x = 50;
static int y = 10;
public class InnerClass {
double myDouble = x;
void show() {
System.out.println(myDouble + 5);
}
}
public static void main(String args[]){
Random rand = new Random();
MainClass obj1 = new MainClass();
MainClass.InnerClass obj2 = obj1.new InnerClass();
int int_random = rand.nextInt(x);
System.out.println(int_random + " :" + " This is the Random Number and its plus 10 is "+ int_random + y);
// obj2.show();
}
}
(int_random + y).+is left associative in Java, meaning"... is " + int_random + yis the same as("... is " + int_random) + yrandomtag, you'd have the same issue with printing fixed values the way you've done it. Randomness has nothing to do with the result.