Created
December 9, 2018 12:51
-
-
Save ilhamarrouf/e11d28698b62df53f5f8f83a9c3ca963 to your computer and use it in GitHub Desktop.
Intorduction to Programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class RandomExample { | |
public static void main(String[] args) { | |
Scanner reader = new Scanner(System.in); | |
int random; | |
System.out.print("Masukkan bilangan a: "); | |
int a = Integer.parseInt(reader.nextLine()); | |
System.out.print("Masukkan bilangan b: "); | |
int b = Integer.parseInt(reader.nextLine()); | |
Random rand = new Random(); | |
if(a >= b) { | |
random = rand.nextInt(a - b + 1) + b; | |
} else { | |
random = rand.nextInt(b - a + 1) + a; | |
} | |
if((random % 2)==0) { | |
System.out.print("Hasil Random bilangan genap: " + random); | |
} else { | |
System.out.print("Hasil Random bilangan genap: " + (random + 1)); | |
reader.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment