Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

How to generate 20 digits random numbers in Java

1 Answer

0 votes
import java.util.Random;

public class Generate20DigitsRandomNumbers_Java {
    public static void main(String[] args) {
        Random rand = new Random();

        for (int count = 0; count < 25; count++) {
            StringBuilder s = new StringBuilder();
            for (int i = 0; i < 20; i++) {
                s.append(rand.nextInt(9) + 1);
            }
            try {
                java.math.BigDecimal dec = new java.math.BigDecimal(s.toString());
                System.out.println(dec);
            } catch (NumberFormatException e) {
                System.out.println("exception: " + e);  
            }
        }
    }
}



 
/*
run:

84756574421792496783
14413788463847238822
42643985739565789833
18547339634665986843
71249211821483617439
14231555824476978229
72768997121796812384
82293487999459484569
36142184665684879268
77688271513875197266
46248955529647868678
41914289548467252987
45247314526415885761
43926765773331618771
16294368381956847726
76398221862221526816
27794464424131433699
24275849315595362583
76143642589217755366
94533555682479967968
69215592464143484436
86169651644185416952
35182447219231878463
74996854642568267719
45157276529775289879
 
*/

 



answered Nov 9, 2024 by avibootz

Related questions

2 answers 81 views
1 answer 60 views
2 answers 230 views
2 answers 497 views
1 answer 66 views
1 answer 94 views
1 answer 83 views
...