+ 1
Im too stupid pls help
import java.util.Scanner; public class Program { public static void main(String[] args) { int[] a = new int[5]; for(int b: a) { a[b] = input.nextInt(); } int d = 0; for (int c: a) { if (a[c]%2==0) { d += a[c]; } } System.out.println(d); } } //some issue in java at line 9 (I think it was and Im too bad to find it and correct it Btw Im new to this forum soooo I dont reall know how it works
8 Antworten
+ 4
Hanz Fenster Make use of the basic for loop in your program because it will suit your code more.
The for-each loop in Java is basically used for traversing the elements in an array or a collection.
You cannot use it to assign values to the array that you have declared.
Also there are a lot of errors and I recommend you to revise the course or topics again to understand what you actually trying to do.
+ 2
First:
You miss the Scanner input declaration
Scanner input = new Scanner(System.in);
Edit:
Second
What Avinesh said.
+ 1
Why b>5 and c>5 ?
It should be b<5 and c<5.
+ 1
Thank you
I still didnt get to the outcome I wanted to
But you helped me a lot
And if you enter the right numbers its even working now! xD
0
Now Im always getting the output 0
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
int[] a = new int[5];
for(int b=0;b>5;b++)
{
a[b] = input.nextInt();
}
int d = 0;
for (int c=0;c>5;c++)
{
if (a[c]%2 == 0)
{
d += a[c];
}
}
System.out.println(d);
}
}
0
Oops
Ty
0
I think you should rename your variable. What does a, b, c, d mean?
0
It was just for trying