Last active
January 3, 2016 09:39
-
-
Save Zulqurnain/f9c4092a0f7b86abf646 to your computer and use it in GitHub Desktop.
Java Program to print the Random Number between given starting and ending value.
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
| package basics; | |
| import java.util.*; | |
| import javax.swing.JOptionPane; | |
| class Basics { // done by Zulqurnain jutt | |
| public static void main(String[] args) { | |
| String s; | |
| int si,ei,numi; | |
| s=JOptionPane.showInputDialog(null, "\t::Starting Range::\t"); | |
| si=Integer.parseInt(s); | |
| s=JOptionPane.showInputDialog(null, "\t::Ending Range::\t"); | |
| ei=Integer.parseInt(s); | |
| s=JOptionPane.showInputDialog(null, "\t::How Much Numbers ?::\t"); | |
| numi=Integer.parseInt(s); | |
| System.out.println(numi+" Random Numbers in range "+si+" - "+ei); | |
| s=null; | |
| if(numi<(ei-si)){ | |
| for(int i=0,sum=0;;i++){ | |
| Random r=new Random(); | |
| int n=(si + (r.nextInt(ei-si+1))); | |
| if(s==null){ | |
| s=Integer.toString(n)+"\n"; | |
| } | |
| else{ | |
| s+=Integer.toString(n)+"\n"; | |
| } | |
| sum+=n; | |
| if(sum==21 && i==numi-1){ | |
| System.out.println(s); | |
| break; | |
| } | |
| else if(i==numi-1){ | |
| i=-1; | |
| sum=0; | |
| s=null; | |
| } | |
| } | |
| } | |
| else{ | |
| System.out.println("Not Pssible in this range"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment