Q:

Calculate Swap The Two Numbers Using Java

0

This Program is used to calculate the swap two numbers using java.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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"); 
} 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now