0
Java program that checks if the given integer is even or odd
I wanted a program that checks if a given array is even or odd. Example: If input is: 5 Output should be: Odd Example2: Input: 42 Output: even I'm new to array, and below is what I did so far: https://code.sololearn.com/cA172A13a199
8 Respostas
+ 2
visph but brianna said to use array and even he/she uses array in his/her program
+ 2
visph đ€ wait...what.....
He wanna check using array,but in sample I/O , I think he also don't need a Loop XD
+ 1
I think your concept of array is not clear!
Error in line 10 , num is not an array!
Error : for taking input you have to run one more for loop
code -
https://code.sololearn.com/cNmKErl74a0U/?ref=app
+ 1
visph correct but I think then there is no difference of using array or Just makes through loop
0
Brianna
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input= new Scanner (System.in);
int num= input.nextInt();
if (num%2==0)
System.out.println("Even");
else
System.out.println("odd");
}
}
If you check only one number at a time then use this code
- 1
or take input in the same loop that you use for testing oddity ;)
- 1
Rishav Tiwari in this specific case, there's no need of array... so having two loops as well as having an array is unuseful ^^
anyway, you could even have to intialize an array and do a first job with the values (and most far in program use the array): in this case, the array is required, but not a specific loop to initialize it ;P
- 1
Rishav Tiwari yes, so we could guess that's as if he/she need to use the array later in program, so having only once loop to initialize the array and testing oddity seems reasonnable ^^