my code should accept 5 numbers, sum them up , average them.. and print the numbers that are below the average
it doesnt appear to be working..why?
import java.io.*;
class Pra1
{
public static void main(String[] args)
{
Console console=System.console();
int size=5;
int number=0;
String allNumbers="";
String Snumber="";
int sum=0;
int avg=0;
int index=0;
int num=0;
for(int i=0;i<size;i++)
{
System.out.println("enter a number");
number=Integer.parseInt(console.readLine());
sum+=number;
allNumbers+=number+",";
}
avg=sum/size;
System.out.println("your average is "+avg);
while(index<allNumbers.length())
{
while(allNumbers.charAt(index)!=',')
{
Snumber+=allNumbers.charAt(index);
index++;
}
num=Integer.parseInt(Snumber);
if(num<avg)
System.out.println(Snumber);
index++;
}
}
}