Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package lab1;
- import java.util.Random;
- /**
- *
- * @author ge0rge04
- */
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void disp(int n)
- {
- if (n%2==0) {
- System.out.print(n+" ");
- if (n==1) return;
- disp(n/2);
- }
- else {
- System.out.print(n + " ");
- if (n==1) return;
- disp(3*n+1);
- }
- }
- public static void disp_m(int n,int count)
- {
- if (n%2==0) {
- if (n==1) {System.out.print(count+ " pasi"); return;}
- disp_m(n/2,++count);
- }
- else {
- if (n==1) {System.out.print(count+ " pasi"); return;}
- disp_m(3*n+1,++count);
- }
- }
- public static void main(String[] args) {
- // TODO code application logic here
- Random gen = new Random();
- int n = gen.nextInt(200);
- long one = System.currentTimeMillis();
- if (n<=100) disp(n);
- else disp_m(n,0);
- long two = System.currentTimeMillis();
- System.out.println("\n"+ (two-one) + " milisecunde");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement