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

16th Jun 2021, 3:21 AM
Brianna
8 Réponses
+ 2
visph but brianna said to use array and even he/she uses array in his/her program
16th Jun 2021, 4:27 AM
Abhiyantā
Abhiyantā - avatar
+ 2
visph 🤔 wait...what..... He wanna check using array,but in sample I/O , I think he also don't need a Loop XD
16th Jun 2021, 4:38 AM
Abhiyantā
Abhiyantā - avatar
+ 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
16th Jun 2021, 3:52 AM
Abhiyantā
Abhiyantā - avatar
+ 1
visph correct but I think then there is no difference of using array or Just makes through loop
16th Jun 2021, 3:58 AM
Abhiyantā
Abhiyantā - avatar
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
17th Jun 2021, 6:05 AM
Gaurav Dixit🇮🇳
Gaurav Dixit🇮🇳 - avatar
- 1
or take input in the same loop that you use for testing oddity ;)
16th Jun 2021, 3:55 AM
visph
visph - avatar
- 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
16th Jun 2021, 4:17 AM
visph
visph - avatar
- 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 ^^
16th Jun 2021, 4:29 AM
visph
visph - avatar