Thread: Arrays, Loops, and Methods.

Results 1 to 2 of 2
  1. #1 Arrays, Loops, and Methods. 
    Registered Member CrypticDev's Avatar
    Join Date
    Oct 2015
    Posts
    7
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    So been learning about Arrays, loops and methods. and here is class I did after watching the lectures.

    Code:
    package xyz.crypticdev.section3;
    
    import java.util.Random;
    
    /**
     * 
     * @author crypticdev
     *
     */
    public class ArraysandMethods {
    	
    	public ArraysandMethods() {
    		
    	}
    	
    	public int[] process(int[] data) {
    		Random random = new Random();
    		
    		for (int i = 0; i < data.length; i++) {
    			data[i] = random.nextInt(100);
    		}
    		return data;
    	}
    	
    	public static void main(String[] args) {
    		int[] data = new int[10];
    		
    		
    		ArraysandMethods am = new ArraysandMethods();
    		data = am.process(data);
    		
    		for (int i = 0; i < data.length; i++) {
    			System.out.println(data[i]);
    		}
    	}
    }
    CONSOLE OUTPUT:
    Code:
    58
    52
    12
    94
    1
    66
    28
    5
    65
    24
    Reply With Quote  
     

  2. #2  
    Valar Morghulis

    Laxika's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    2,813
    Thanks given
    1,804
    Thanks received
    274
    Rep Power
    2128
    Quote Originally Posted by CrypticDev View Post
    So been learning about Arrays, loops and methods. and here is class I did after watching the lectures.

    Code:
    package xyz.crypticdev.section3;
    
    import java.util.Random;
    
    /**
     * 
     * @author crypticdev
     *
     */
    public class ArraysandMethods {
    	
    	public ArraysandMethods() {
    		
    	}
    	
    	public int[] process(int[] data) {
    		Random random = new Random();
    		
    		for (int i = 0; i < data.length; i++) {
    			data[i] = random.nextInt(100);
    		}
    		return data;
    	}
    	
    	public static void main(String[] args) {
    		int[] data = new int[10];
    		
    		
    		ArraysandMethods am = new ArraysandMethods();
    		data = am.process(data);
    		
    		for (int i = 0; i < data.length; i++) {
    			System.out.println(data[i]);
    		}
    	}
    }
    CONSOLE OUTPUT:
    Code:
    58
    52
    12
    94
    1
    66
    28
    5
    65
    24
    I do a code review for you if thats what you want.



    These are the biggest problems I found. I hope you learned something.
    Reply With Quote  
     

  3. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 3
    Last Post: 08-31-2009, 01:46 AM
  2. Replies: 4
    Last Post: 08-26-2009, 07:14 PM
  3. Grabing a variable and method
    By Groovy in forum Help
    Replies: 2
    Last Post: 07-13-2009, 08:27 PM
  4. Replies: 2
    Last Post: 05-30-2008, 01:08 AM
  5. Voids, Booleans, And Methods.
    By IGotSkillz in forum Tutorials
    Replies: 18
    Last Post: 02-16-2008, 11:50 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •