Results 1 to 3 of 3
- 03-09-2010, 03:33 AM #1
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
- 03-09-2010, 06:41 AM #2
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
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
- 03-09-2010, 07:33 AM #3
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
-
JAVA Project
By kappasig84 in forum New To JavaReplies: 6Last Post: 12-13-2009, 09:28 PM -
Java Project
By dessen in forum JCreatorReplies: 4Last Post: 04-18-2009, 04:38 PM -
Java Project
By Smirre in forum New To JavaReplies: 16Last Post: 11-17-2008, 08:37 PM -
Help with Java project
By ducster in forum New To JavaReplies: 11Last Post: 12-03-2007, 03:08 AM -
Java Project Help
By Gambit17 in forum New To JavaReplies: 3Last Post: 11-05-2007, 11:53 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks