qerubin |
|
| Un semplice programmino che estrae numeri casuali da 1 a 100, estremi compresi. Può estrarre più volte lo stesso numero. CODICE import javax.swing.*; import java.io.*; public class randomnumeri{ public static void main (String args[]) throws IOException{ int n=Integer.parseInt(JOptionPane.showInputDialog("Questo programma estrae numeri casuali da 1 a 100.\nQuanti numeri estrarre?")); char opt=0; String extr,ris; System.out.println("I numeri estratti sono:"); for(int i=0; i<n; i++) { ris=""; double rand=Math.random(); double extr2=rand*100; extr=String.valueOf(extr2); if(extr.charAt(1)=='.') ris=ris+extr.charAt(0); else if(extr.charAt(2)=='.') ris=ris+extr.charAt(0)+extr.charAt(1); else ris=ris+extr.charAt(0)+extr.charAt(1)+extr.charAt(2); int a=Integer.parseInt(ris)+1; System.out.println(a); } } }
|
| |