Chance problems program

Generating Chance of getting 0 is 75% percent and 1 is 25% percent probability

  1. import java.util.Random;

  2. public class Chance {

  3. public static int getChance(){
  4. Random randomNumber = new Random();
  5. int randomGenerator = randomNumber.nextInt(100);
  6. System.out.println(randomGenerator);
  7. if(randomGenerator < 75)
  8. return 0;
  9. else 
  10. return 1;
  11. }
  12. public static void main(String[] args) {

  13. for(int i=0;i<10;i++){
  14. System.out.println(Chance.getChance());
  15. }
  16. }

  17. }


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation