Write a program to display numeric value in reverse order.
Ex: I have given a number like 7584, It should display in
reverse order like 4857.
Answers were Sorted based on User's Feedback
Answer / pankaj
int n=1856,rem,n1,temp=0;
for(int i=0;n>=1;i++)
{
rem=n%10;
n=n/10;
temp=(temp*10)+rem;
}
| Is This Answer Correct ? | 7 Yes | 0 No |
Answer / srikanth
import java.io.*;
class palin{
public static void main(String as[]){
try{
InputStreamReader isr=null;
BufferedReader br=null;
br=new BufferedReader(new InputStreamReader(System.in));
int num=Integer.parseInt(br.readLine());
System.out.println(num);
int n=num;
int rev=0;
System.out.println("number");
System.out.println(num);
for(int i=0;i<=num;i++){
int r=num%10;
num=num/10;
rev=rev*10+r;
i=0;
}
System.out.println("after reversing"+rev);
if(n==rev){
System.out.println("number is palic");
}
else{
System.out.println("number is not palic");
}
}catch(Exception e){
System.out.println(e);
}
}
}
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / selvi
import java.util.Scanner;
public class IntReverseOrder
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
StringBuffer sb = new StringBuffer();
int remainder;
while(num>0)
{
remainder = num%10;
sb = sb.append(remainder);
num = num/10;
}
System.out.println("Reverse Order = "+sb);
}
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / pradyumna
public class Test1 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("1234");
System.out.println(s1);
s1.reverse();
System.out.println(s1);
}
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / deepak
public class A
{
public static void main(String str[])
{
String s="7584";
System.out.println(s);
s.reverse();
System.out.println(s);
}}
| Is This Answer Correct ? | 7 Yes | 9 No |
what is the main use of the RequestDispatch object, how we this in realtime project
What do you understand by j2ee?
what is the difference between servlets and jsp?
How do you run a java program?
Which framework is best for java?
How does j2ee application work?
What is difference between java and core?
static variable is a class variable which value remains constant for the entire class?? variable means value is changed....hear value is not changed... why it is called static variable
Which is best eclipse for java?
What is java actionlistener?
when i m calling java for web browser . so browser it's not support. show error in browser: internal error occur. java.lang.NoClassDefFoundError. will you give me solution why it's not starting browser.? is there any consult with .net framework2.0?
What are j2ee concepts?