Swapping digits in Four digit variable
2 posters
LFPS - Forum :: Study Corner :: Computers :: Java :: Snippets
Page 1 of 1
Swapping digits in Four digit variable
- Code:
class Gattu
{
static int swap(int a)
{
int e=a/1000; //a=8719//
int g=a%1000; //g=719//
int o=g/100; //o=7//
int j=g%100; //j=19//
int z=j*100; //z=1900//
int y=e*10; //o=70//
int w=o; //w=8//
int v=z+y+w;
return(v);
}
public static void main(String[] args)
{
int x=Integer.parseInt(args[0]);
int p=Gattu.swap(x);
System.out.println("the answer is "+p);
}
}
- Code:
E:\Program Files\Java\jdk1.6.0\bin>java Gattu 8719
the answer is 1987
shirish.vogga- New LSF Member
- Posts : 3
LFPS - Forum :: Study Corner :: Computers :: Java :: Snippets
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Feb 14, 2012 9:02 pm by Sujith
» Kolaveri Di
Tue Nov 22, 2011 5:11 pm by Sujith
» Plane of Remembrance
Mon May 23, 2011 7:44 am by Sujith
» Board Exam Results 2011
Fri May 13, 2011 10:19 pm by Sujith
» Source Code
Wed May 04, 2011 8:06 pm by Sujith
» Rio
Wed May 04, 2011 8:04 pm by Sujith
» Fast and Furious 5
Wed May 04, 2011 7:56 pm by Sujith