Computer Science, asked by Monkiko, 3 months ago

W.A.P to input a number. Display all numbers in reverse form if it is an even number in JAVA.​

Answers

Answered by himanshu2006vps
1

Answer:

import java.util.Scanner;

class ReverseNumberEven

{

public static void main(String args[])

{

int num=0;

int reversenum =0;

System.out.println("Input your number and press enter: ");

Scanner in = new Scanner(System.in);

num = in.nextInt();

while( num != 0 )

{

reversenum = reversenum * 10;

reversenum = reversenum + num%10;

num = num/10;

}

if (reversenum%2==0)

{

System.out.println("Reverse of input number is: "+reversenum);

else

System.out.println("Enter even number");

}

}

}


Monkiko: Thanks for your help but can you please solve this without using scanner class:)
himanshu2006vps: scanner is important as value is to be inputted by uset
himanshu2006vps: user*
himanshu2006vps: Without scanner user cannot input values bt their own
Monkiko: oh ok
Monkiko: thanks btw
Monkiko: :)
himanshu2006vps: you're welcome
Answered by BrainlyProgrammer
3

Question:-

  • W.A.P to input a number. Display all numbers in reverse form if it is an even number in JAVA.

Code:-

package Coder;

import java.util.*;

public class EveReverse

{

public static void main (String ar [])

{

System.out.println("Enter a number");

int n=sc.nextInt();

int r=0;

if(n%2==0)

{

while (n!=0)

{

r=r*10+(n%10); n/=10;

}

System.out.println("Number is even, Reverse if the number is:"+r);

}

else

System.out.println("Number not Even");

}

}                //ShortestCodePossible

Variable Description:-

  1. n:- to accept the number as input
  2. r:- to reverse the number if it's even

Code Explanation:-

  1. The program accepts the user to input 1 number
  2. Then it checks if the number is even or not.
  3. if even then it reverses the number and store it in variable 'r'.

•Output Attached.

Attachments:

Anonymous: Fabulous! : )
BrainlyProgrammer: Thanks... :D
Similar questions