This article describes the simple number processing classes and usages of Java implementation. Share it for your reference, as follows:
A program has been developed with the following functions: Get 6 integers between 2 and 32 and obtain the sum of these 6 even numbers.
In this example, Math.random() is referenced, but actually implements Random.nextDouble() . However, for the general use of random, we are used to using Math.random() mainly because it si simpler to use
/** * A program has been developed with the following functions: * Get 6 integers between 2 and 32 and get the sum of these 6 even numbers. * <p> * In this example, Math.random() is referenced, but actually implements Random.nextDouble(). * However, for the general use of random, we are used to using Math.random() mainly because it is simpler to use * @author HAN * */public class DataTreatementClassApps { public static void main(String[] args) { System.out.println("Wulin.com test result: "); int i=0; int sum=0; while(i<6){ int a=(int) (2+Math.random()*30); if (a%2==0){ //Please method System.out.println(a); sum=sum+a; i++; } } System.out.println("sum of six even numbers:"+sum); }}Running results:
For more information about Java algorithms, readers who are interested in this site can view the topics: "Java Data Structure and Algorithm Tutorial", "Summary of Java Operation DOM Node Tips", "Summary of Java File and Directory Operation Tips" and "Summary of Java Cache Operation Tips"
I hope this article will be helpful to everyone's Java programming.