I have problem with 3 i 5 points with version 2
Version 1
package pl.codegym.task.task04.task0428;
/*
Liczba dodatnia
*/
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
//tutaj wpisz swój kod
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(r.readLine()), b = Integer.parseInt(r.readLine()), c = Integer.parseInt(r.readLine());
ArrayList<Integer> lista = new ArrayList<Integer>();
lista.add(a);
lista.add(b);
lista.add(c);
int count=0;
for(int i = 0; i < lista.size(); i++)
{
if(lista.get(i) > 0 )
{
count++;
}
}
System.out.println(count);
}
}
Version 2
package pl.codegym.task.task04.task0428;
/*
Liczba dodatnia
*/
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
//tutaj wpisz swój kod
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(r.readLine()), b = Integer.parseInt(r.readLine()), c = Integer.parseInt(r.readLine());
ArrayList<Integer> lista = new ArrayList<Integer>();
lista.add(a);
lista.add(b);
lista.add(c);
int count=0;
for(int i = 0; i < lista.size(); i++)
{
if(lista.get(i) > 0 )
{
count=+1;
}
}
System.out.println(count);
}
}
Dawid
Poziom 13
Why version 1 is good but second no :D ?
Rozwiązane
Komentarze (3)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
DawidExpert
1 maja 2023, 10:19
Thank you.
+1
Thomas
28 kwietnia 2023, 12:21rozwiązanie
you confused += and =+
eg.
is synonym to
is synonym to
in each iteration you assign 1 to count
on the other hand
is synonym to
is synonym to
+3
Thomas
3 maja 2023, 13:46
To be absolutely precise, i += i is not really synonym to i = i + 1 it's synonym to i = (T) (i + 1), where T is the type of the variable you assign the result. Two examples showing the problems and the benefits. This may not be very interesting at this point of learning, though ;)
+1