Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Random numbers  (Read 1526 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: June 01, 2007, 07:59:46 PM »

Here is a little demo that prints out random numbers:

Code
GeSHi (java):
  1. public class Random{
  2. public static void main(String[] args) {
  3. int tmp = 0;
  4.  
  5. for (int i = 0; i < 10; i++){
  6. int randomNumbers = (int) (1 + (Math.random() * 10));
  7. System.out.println("Random number " +  tmp + " : " + randomNumbers);
  8. tmp++;
  9. }
  10. }
  11. }
  12.  
Created by GeSHI 1.0.7.20

Screenshot:
http://img396.imageshack.us/img396/3590/randommj1.png
Random numbers


ALSO known as inFamous to some faggots at Rune-server!
« Last Edit: October 09, 2009, 06:03:21 AM by _ikram » Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Croco
Staff
Member
*

Reputation: 1
Offline Offline
Gender: Male
Posts: 64
Referrals: 0

Awards
« Reply #1 on: June 02, 2007, 03:01:43 PM »

Code
GeSHi (java):
  1. // file name Bool.java
  2.  
  3. import java.util.*;
  4.  
  5. public class Bool {
  6.  
  7. public static void main(String[] args) {
  8. Random rand = new Random();
  9. int i = rand.nextInt(100);
  10. int j = rand.nextInt(100);
  11. System.out.println("i = " + i);
  12. System.out.println("j = " + j);
  13. System.out.println("i > j is " + (i > j));
  14. System.out.println("i < j is " + (i < j));
  15. System.out.println("i >= j is " + (i >= j));
  16. System.out.println("i <= j is " + (i <= j));
  17. System.out.println("i == j is " + (i == j));
  18. System.out.println("i != j is " + (i != j));
  19. // Treating an int as a boolean is not legal Java:
  20. //! System.out.println("i && j is " + (i && j));
  21. //! System.out.println("i || j is " + (i || j));
  22. //! System.out.println("!i is " + !i);
  23. System.out.println("(i < 10) && (j < 10) is "
  24. + ((i < 10) && (j < 10)) );
  25. System.out.println("(i < 10) || (j < 10) is "
  26. + ((i < 10) || (j < 10)) );
  27.  
  28. } // main
  29. } // Bool
  30.  
  31.  
Created by GeSHI 1.0.7.20

Quote

i = -???       (this mean the number isn't known)
j = -???
i > j is (true|false) ( | means or )
i < j is (true|false)
i >= j is (true|false)
i <= j is (true|false)
i == j is (true|false)
i != j is (true|false)
(i < 10) && (j < 10) is (true|false)
(i < 10) || (j < 10) is (true|false)


Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here