TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Calculate Swap The Two Numbers Using Java
Senthilvelan Sambamoorthy
Aug 13
2016
Code
660
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
ssva20.rar
/* SWAP THE TWO NUMBERS */
import
java.io.*;
import
java.text.*;
class
ssva20
{
public
static
void
main(String arg[])
throws
IOException
{
BufferedReader obj=
new
BufferedReader(
new
InputStreamReader(System.in));
System.out.println(
"\n SWAP TWO NUMBERS"
);
System.out.println(
" ---- --- -------"
);
System.out.println(
"\n\tI N P U T"
);
System.out.println(
"\t- - - - -"
);
System.out.print(
"\n ENTER THE FIRST NUMBER (M) : "
);
double
m=Double.parseDouble(obj.readLine());
System.out.print(
"\nENTER THE SECOND NUMBER (N) : "
);
double
n=Double.parseDouble(obj.readLine());
NumberFormat nf=NumberFormat.getInstance();
nf.setMinimumFractionDigits(
2
);
m=m+n;
n=m-n;
m=m-n;
System.out.println(
"\n\tO U T P U T"
);
System.out.println(
"\t- - - - - -"
);
System.out.println(
"\n THE SWAP OF FIRST NUMBER (M) IS : "
+nf.format(m));
System.out.println(
"\nTHE SWAP OF SECOND NUMBER (N) IS : "
+nf.format(n));
System.out.println(
"\n\n"
);
}
}
Java