You need to sign in to do that
Don't have an account?
TUSHAR KHORGADE
hello all i am getting error pls coorect me if i am worng i want to print even n odd number with there count with help of using map
Create a map populate it with two records Odd and Even. Run a loop from 1-50, if you find a even number increase the count for even named record in map or else increase count of odd named record. Odd and even are keys, counts are values. Example map syntax: Map<String,integer> CountNumber = new map<String,Inetger>({'Even':4},{'Odd':3});
my code is this
public class NumberTest {
integer oddCount = 0;
integer evenCount = 0;
Map<string,integer> countNumber = new Map<string,integer>();
for(int i=1;i<=50;i++)
{
if(a[i] % 2 != 0){
countNumber.put('Odd',oddCount++);
}
else{
countNumber.put('Even',evenCount++);
}
}
}
my code is this
public class NumberTest {
integer oddCount = 0;
integer evenCount = 0;
Map<string,integer> countNumber = new Map<string,integer>();
for(int i=1;i<=50;i++)
{
if(a[i] % 2 != 0){
countNumber.put('Odd',oddCount++);
}
else{
countNumber.put('Even',evenCount++);
}
}
}
I see two main mistakes in your code.
1) Int data type is not valid in APEX. Try using integer.
2) % operator is not valid in Apex. Try using the below line.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
I see two main mistakes in your code.
1) Int data type is not valid in APEX. Try using integer.
2) % operator is not valid in Apex. Try using the below line.
If this solution helps, Please mark it as best answer.
Thanks,