I have to:
I can't figure out how to do that, here is my code so far, any help would be appreciated.
public class december2012 {
public static void main(String[] args) {
int sum=0;
Scanner input = new Scanner(System.in);
int i=1;
int [] array = new int[i];
while( i > array.length || sum <= 100) {
System.out.println("Write in the " + i + " number") ;
array[i]=input.nextInt();
sum=+array[i];
System.out.println("sum is " + sum);
}
}
}
int i = 0; // array starts from 0
int [] array = new int[100]; // create larger array
while(i < array.length && sum <= 100) // i should be less then length
// && instead of ||
{
System.out.println("Write in the " + i + " number") ;
array[i] = input.nextInt();
sum += array[i]; // += instead of =+
System.out.println("sum is " + sum);
i++; // increment i
}
Ideone DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With