lundi 20 avril 2020

Adding to a random number

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();
    }
}



Aucun commentaire:

Enregistrer un commentaire