AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
3. Our Experts are looking for yours ?.

# corejava-programming: Reverse Jalaj number

 Jalaj was deeply studying in the afternoon and came across a concept called as reverse of a number Hearing this for the first time, he was eager to learn and searched the Internet and decided to design a program, which can reverse any number. But, he could not convert his logic into code. So, he is now requesting you to design a very efficient method to reverse a number and print it as a EVEN or ODD, as the case may be. Input The first line contains T, the number of test cases. Followed by T lines each contains a single number. Output: For every test case print the EVEN if reverse of the given number is even, else print ODD. Constraints: 1<=T<=10000 1<=N<=10 raised to the power 100 Sample Input 5 1 3 6 15 23 Sample Output ODD 1 ODD 3 EVEN 6 ODD 15 EVEN 23 corejava x 353programming x 169 Posted On : 2016-11-01 13:05:03.0 Akash Prasad 2550 4

 Check this code and let me know if the conditions are satisfied or not. import java.util.Scanner; public class RevEvenOdd { public static void main(String[] args) { int t; int temp = 0; Scanner s = new Scanner(System.in); t = s.nextInt(); int[] a = new int[t]; if(t>=1 && t<=10000) { for (int i = 0; i < t; i++) { a[i] = s.nextInt(); } for(int i=0; i0) { temp = temp*10 + a[i] %10; a[i] = a[i]/10; } a[i] = temp; } for(int i = 0 ; i < t ; i++) { if(a[i] % 2 != 0) { temp = 0; while(a[i]>0) { temp = temp*10 + a[i] %10; a[i] = a[i]/10; } a[i] = temp; System.out.println("ODD :" +a[i]); } else if(a[i] % 2 == 0) { temp = 0; while(a[i]>0) { temp = temp*10 + a[i] %10; a[i] = a[i]/10; } a[i] = temp; System.out.println("EVEN :"+a[i]); } } } } } Posted On : 2016-11-05 17:12:08 Satisfied : 0 Yes  3 No 5

 import java.util.Scanner; public class ReverseOddEven { public static void main(String[] args) { Scanner input=new Scanner(System.in); int T=input.nextInt(); Integer N=0; Integer R=0; if(1<=T && T<=10000 ){ System.out.println(""); for(int i=1;i<=T;i++){ try{ N=input.nextInt(); if(1<=N && N<=Math.pow(100, 10)){ if(N.toString().length()>1){ R=Integer.parseInt(new StringBuffer(N.toString()).reverse().toString()); }else{ R=N; } System.out.println((R%2==0?"EVEN":"ODD")+ " "+N); }else{ System.out.println("Invalid Input!"); break; } }catch (Exception e) { e.printStackTrace(); break; } } }else{ System.out.println("Invalid Input!"); } } } Note: --------------------------- While giving input press enter or one more new line after last number as below: Input: ---------------------------------- 5 1 3 6 15 23 Output: -------------------------- ODD 1 ODD 3 EVEN 6 ODD 15 EVEN 23 Posted On : 2016-11-09 23:29:57 Satisfied : 1 Yes  0 No Rishi Kumar 523188239021Reply This Thread 4

 Check this updated code , As per mentioned Sample input and output i think my code satisfies the condition.Let me know if the conditions are satisfied or not. import java.util.Scanner; public class RevEvenOdd { public static void main(String[] args) { int t; int temp = 0; Scanner s = new Scanner(System.in); t = s.nextInt(); int[] a = new int[t]; if(t>=1 && t<=10000) { for (int i = 0; i < t; i++) { a[i]=s.nextInt(); } for (int i = 0; i < a.length; i++) { if(a[i]>=1&&a[i]<=Math.pow(10,100)) { temp = 0; while(a[i]>0) { temp = temp*10 + a[i] %10; a[i] = a[i]/10; } a[i] = temp; } } for(int i = 0 ; i < a.length ; i++) { if(a[i] % 2 != 0) { if(a[i]>=1&&a[i]<=Math.pow(10,100)) { temp = 0; while(a[i]>0) { temp = temp*10 + a[i] %10; a[i] = a[i]/10; } a[i] = temp; System.out.println("ODD :" +a[i]); } else { System.out.println("ODD :" +a[i]); } } else if(a[i] % 2 == 0) { if(a[i]>=1&&a[i]<=Math.pow(10,100)) { temp = 0; while(a[i]>0) { temp = temp*10 + a[i] %10; a[i] = a[i]/10; } a[i] = temp; System.out.println("EVEN :"+a[i]); } else { System.out.println("EVEN :" +a[i]); } } } } } } My code shows exactly mentioned in the as in the sample input and output. Sample Input 5 1 3 6 15 23 Sample Output ODD 1 ODD 3 EVEN 6 ODD 15 EVEN 23 Posted On : 2016-11-10 20:11:22 Satisfied : 1 Yes  0 No 3
Hi sudheerkumar,
What´s the problem in my code? Isn´t it shorter and easy to understand?
Rishi Kumar
523  1882  39021
Posted On :2016-11-10 21:46:13.0
No Issues in your code.As per my understanding first we need to take all elements from console and print the all elements at a time once the condition satifies.

But in your code each element takes from console and print them.
Find the below output details from your code and my code.

My code takes all elements at time and print them all elements:

Posted On :2016-11-11 20:31:07.0
All right. My code also take all elements at a time. After running the code, just paste all inputs and press Enter. It´ll display the desired output.
Rishi Kumar
523  1882  39021
Posted On :2016-11-12 14:50:12.0