Topic 1: calculate your birth date number of days from today?
First, the source
date.java
/ ** Date of Birth calculated elapsed day number * 1 Method * / Package cn.edu.ccut.w1120t1; Import the java.util.Calendar; Import java.util.Date; Import java.util.Scanner; public class DATE { public static void main (String [] args) { Scanner Reader = new new Scanner (System.in); System.out.print ( "Please enter your birth date - year, month, day three values \ the n-" ); int = year reader.nextInt (); int month The = reader.nextInt (); int Day reader.nextInt = (); //Acquires date of birth from the keyboard Calendar Birthday Calendar.getInstance = (); // initialize a calendar object birthday.set (year, month The-. 1, Day); // set the calendar is the birthday Long MSl birthday.getTimeInMillis = (); / / calculated value of time in milliseconds from the 1970.01.01.00:00:00 calendar nowday Calendar.getInstance = (); // initialize a calendar object nowday.setTime ( new new a Date ()); // set the value of the current calendar time Long MS2 = (nowday.getTimeInMillis () - MSl) / 1000/60/60/24; // calculate days apart System.out.print ( "date of birth from today" + ms2 + "days" ); } }
Second, the success Screenshots
Problem 2: randomly generating a random integer number between [1,100]. [30,70]? What is the law?
First, the source
number.java
/ ** Title 2: randomly generating a random integer number between [1,100]. [30,70]? What is the law? Method 1 * * / Package cn.edu.ccut.w1120t2; public class Number { public static void main (String [] args) { of System.out.print ( "50 integer random number between [1,100] is: \ n-\ n-" ); int SUM = 0; // general law counter int SUM1 = 0; // every ten counter law for ( int I =. 1; I <= 50; I ++ ) { int NUM = ( int ) ( math.random () * + 100. 1); // randomly generates an integer random number between [1,100] IF (NUM> && NUM = 30 <= 70) { //Determines whether [30, 70] of System.out.print (NUM + "" ); SUM ++; SUM1 ++ ; } the else { of System.out.print (NUM + "" ); } IF (I / 10> 0 && I 10% 0 == ) { of System.out.print ( "\ N10 has a" + sum1 + "th in [30, 70] \ n-\ n-" ); SUM1 = 0 ; } } of System.out.print ( "50 th there are "+ sum +" therebetween th " ); } }
Second, the success Screenshots