Nov1ce's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
38 (0.03 per day)
Joined:
04-March 11
Profile Views:
944
Last Active:
User is offline Mar 13 2014 11:03 AM
Currently:
Offline

Previous Fields

Country:
NG
OS Preference:
Windows
Favorite Browser:
Who Cares
Favorite Processor:
Intel
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   Nov1ce has not set their status

Posts I've Made

  1. In Topic: display array to textArea, but How?

    Posted 11 Mar 2014

    Iterate through the loop and append each element in the array to the text area.
    <<start loop>>
    textArea.append(arrayOfStrings[index])
    <<end>>
    
    
  2. In Topic: Problem for generate random number

    Posted 5 Mar 2014

    View Postg00se, on 05 March 2014 - 09:45 AM, said:

    Quote

    If there's a way to get the current number as odd and the next as even while iterating through the random numbers at the same time, I'd be glad to hear it!
    OP already has that right (but with the wrong number of iterations)

    I doubt if he does. Looking at his code, he's printing out the counters not the actual random numbers!
  3. In Topic: Problem for generate random number

    Posted 5 Mar 2014

    View Postg00se, on 05 March 2014 - 09:15 AM, said:

    Quote

    @g00se: How would you place the iteration number, even number and odd number in that tabular fashion?
    I'd use System.out.printf

    Ok??? What am referring to is how you plan on printing both the odd and even numbers while iterating through the loop and checking if they are odd or even.
    Cause my logic is to get all odd and even numbers into a collection since a particular number can only belong to one of the two. And then printing it after all iterations are complete!
    If there's a way to get the current number as odd and the next as even while iterating through the random numbers at the same time, I'd be glad to hear it!
  4. In Topic: Problem for generate random number

    Posted 5 Mar 2014

    View Postg00se, on 05 March 2014 - 07:38 AM, said:

    Quote

    In order to generate the sort of results according to the question, you might have to explore some data structures.

    Nope, the spec says nothing about storage - just display

    My comment: "In order to generate the sort of results according to the question, you MIGHT have to explore some data structures."

    @g00se: How would you place the iteration number, even number and odd number in that tabular fashion?
  5. In Topic: Problem for generate random number

    Posted 5 Mar 2014

    In order to generate the sort of results according to the question, you might have to explore some data structures.
    Below is what you're trying to achieve.
    import java.util.ArrayList;
    import java.util.Random;
    
    public class OddOrEven{
    	public static void main(String[] args) {
    	
    		Random randomGen = new Random();
    		int randomNumber = 0;
    			
    		ArrayList<Integer> evenNumbers = new ArrayList<Integer>();
    		ArrayList<Integer> oddNumbers = new ArrayList<Integer>();
    		
    		for (int i = 1; i <= 100; i++){
    			randomNumber = randomGen.nextInt(1000) + 1;
    			
    			if (isEven(randomNumber)){
    				evenNumbers.add(randomNumber);
    			}else{
    				oddNumbers.add(randomNumber);
    			}
    		}
    		
    		int numberOfIterations = evenNumbers.size() > oddNumbers.size() ? evenNumbers.size() : oddNumbers.size();
    		
    		String currentEven, currentOdd;
    		System.out.println("Iteration\t" + "Even\t" + "Odd");
    		
    		for (int i = 0; i < numberOfIterations; i++){
    			if (i < evenNumbers.size()){
    				currentEven = "" + evenNumbers.get(i);
    			}else{
    				currentEven = "";
    			}
    			
    			if (i < oddNumbers.size()){
    				currentOdd = "" + oddNumbers.get(i);
    			}else{
    				currentOdd = "";
    			}
    			
    			System.out.println( i+1 + "\t\t" + currentEven + "\t" + currentOdd);
    		}
    	
    		System.out.println("Total:\t\t" + evenNumbers.size() + "\t" + oddNumbers.size());
    	}
    
    	public static boolean isEven(int n) {
    		if ((n % 2) == 0)
    			return true;
    		else
    			return false;
    	}
    }
    
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
October 9
Gender:
Location:
Nigeria
Interests:
Software Development, IVRS Development, Database Administration.
Programming Languages:
Java SE & EE, VB.NET

Contact Information

E-mail:
Private

Friends

Comments

Nov1ce has no profile comments yet. Why not say hello?