Results 1 to 3 of 3
  1. #1
    Aimuthe's Avatar
    Aimuthe is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Need help on a Java project Please!!

    So i'm doing my projects for my java class, and this came up..

    - Write a program that takes 10 integers as input. The program places the even integers into an array called evenList, the odd integers into an array called oddList, and the negative integers into an array called negativeList.The program displays the contents of the three arrays after all of the integers have been entered.


    ...I don't quite get how to do this so can someone help me since i'm just begging learning this, and i have to turn this in by next week ><. Thank you if u can help me, i would really appreciate it :D

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    its pretty easy

    in your program

    use scanner by taking the inputs
    create 3 arrays of length 10.
    and put the input in respective arrays by using fundamental maths

  3. #3
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    160
    Rep Power
    5

    Default

    hi,
    by using simple array with size 10 will make out put incorrect and may cause null pointer exception
    use this
    /**
    *
    */
    package abstractegs;

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.ArrayList;

    /**
    * @author on Mar 9, 2010
    *
    */
    public class ChecktheNumbers {

    /**
    * @param args
    */
    public static void main(String[] args) {
    ArrayList<Integer>negative=new ArrayList<Integer>();
    ArrayList<Integer>even=new ArrayList<Integer>();
    ArrayList<Integer>odd=new ArrayList<Integer>();
    for(int i=0;i<10;i++)
    {
    System.out.println("enter the number");
    try {
    BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
    int num=Integer.parseInt(BR.readLine());
    if(num<0)
    {
    negative.add(num);
    }
    else if(num%2==0){
    even.add(num);
    }
    else{
    odd.add(num);
    }
    } catch (Exception e) {
    System.out.println("Exce"+e);
    }
    }

    for (int string : negative) {
    System.out.println("negativeList"+string);

    }
    for (int string : even) {
    System.out.println("evenList"+string);

    }
    for (int string : odd) {
    System.out.println("oddList"+string);

    }



    }


    }

Similar Threads

  1. JAVA Project
    By kappasig84 in forum New To Java
    Replies: 6
    Last Post: 12-13-2009, 09:28 PM
  2. Java Project
    By dessen in forum JCreator
    Replies: 4
    Last Post: 04-18-2009, 04:38 PM
  3. Java Project
    By Smirre in forum New To Java
    Replies: 16
    Last Post: 11-17-2008, 08:37 PM
  4. Help with Java project
    By ducster in forum New To Java
    Replies: 11
    Last Post: 12-03-2007, 03:08 AM
  5. Java Project Help
    By Gambit17 in forum New To Java
    Replies: 3
    Last Post: 11-05-2007, 11:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •