Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


mudita sinha
swapping
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners


WAP to swap 2 digits without using the 3rd variable!!!....m new to java so plz guys if u kno the answer then plz help me!!!plzzz

Advertisement
View Answers

February 6, 2010 at 10:29 AM


Hi Friend,

Try the following code:

import java.util.*;
class Swapping{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("Enter Number 1: ");
int num1=input.nextInt();
System.out.println("Enter Number 2: ");
int num2=input.nextInt();
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
System.out.println("After swapping, num1= "+num1+" and num2= "+num2);
}
}

Thanks


Related Tutorials/Questions & Answers:
swapping - Java Beginners
swapping   How to swap values of two variable without using third..., Try the following code: class Swapping { public static void main(String... = num1 - num2; num1 = num1 - num2; System.out.println("After swapping, num1
swapping - Java Beginners
;Hi Friend, Try the following code: import java.util.*; class Swapping...; num2=num1-num2; num1=num1-num2; System.out.println("After swapping
Advertisements
swapping - Java Interview Questions
swapping  if input is 123456 then output should be 214365. how to do it using java code?  Hi friend, As your requirement Code to swapping : import java.io.*; public class SwapNumbers { public static void
Dynamically Swapping Images with JavaScript
Dynamically Swapping Images with JavaScript  ... the numbers Swapping in JavaScript and create a  JavaScript program. Image Swapping in JavaScript:- In JavaScript, Numbers Swapping means interchange
Swapping of two numbers
Swapping of two numbers      ... program to calculate swap of two numbers. Swapping is used where  you want... swap the numbers. To swap two numbers first we have to declare a class Swapping
Swapping of two numbers in java
Swapping of two numbers in java In this example we are going to describe swapping of two numbers in java  without using the third number in java. We... values from the command prompt. The swapping of two numbers is based on simple
Swapping of two numbers without using third variable
Swapping of two numbers without using third variable In this tutorial we will learn about swapping of two number in java without using third variable. This is simple program to swap two value using arithmetic operation Swapping of two
Bubble Sort in Java
is sorted. Swapping is followed carried out repeatedly till the list is sorted. Bubble..., it goes back to first pair. The process of comparing, swapping and returning to first
JAVA PROGRAMMING
JAVA PROGRAMMING  Write an OVERLOADED FUNCTION in java that swaps(interchanges) 2 user given numbers.(one integer and one float value) and displays the result after swapping. Invoke the function in a class
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2] = {2,3}; printf("before swapping: %d %d\n",a[0],a[1]); //a[0] ^= a[1]; //a[1...] ^= a[1]; //this didn't work correctly why? printf("after swapping: %d %d\n
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2] = {2,3}; printf("before swapping: %d %d\n",a[0],a[1]); //a[0] ^= a[1]; //a[1...] ^= a[1]; //this didn't work correctly why? printf("after swapping: %d %d\n
PHP Call By Reference
"<b>Before swapping values are \$var1= $var1 & \$var2= $var2... swapping values are \$var1= $var1 & \$var2= $var2 <br/></b>"; ?> Output: Before swapping values $var1= 34 & $var2= 90
function arguments in java
code   public class Swapping{ static void swap(int i,int j){ int temp=i; i=j; j=temp; System.out.println("After swapping i = " + i + " j...; System.out.prinln("Before swapping i="+i+" j="+j); swap(i,j
Swap two numbers without using third variable
: import java.util.*; class Swapping { public static void main(String[] args...; num1 = num1 - num2; System.out.println("After swapping, num1= " + num1...: 20 Enter Number 2: 10 After swapping, num1=10 and num2=20
xor operator not working correctly with array
xor operator not working correctly with array  main { int a[2] = {2,3}; printf("before swapping: %d %d\n",a[0],a[1]); //a[0] ^= a[1]; //a[1...] ^= a[1]; //this didn't work correctly why? printf("after swapping: %d %d\n
Program to swap the string
(); System.out.println(); System.out.println("Before swapping...("After swapping:"); System.out.println("st1="+st1+" and st2="+st2
java - Java Beginners
: class Swapping { public static void main(String[] args) { int num1 = 10... - num2; System.out.println("After swapping, num1= " + num1 + " and num2
java - JSP-Servlet
place. thanks!!  Hello Without swapping u can pay money
java
pament in my account through A.T.M. tranjections or swapping machin.could u give
JDBC
selection?   public class Swapping{ static void swap(int i,int j){ int temp=i; i=j; j=temp; System.out.println("After swapping i = " + i + " j...; System.out.prinln("Before swapping i="+i+" j="+j); swap(i,j
confusion
, 1)For swapping, use following code: int num1=5,num2=10; num1 = num1
Remove From Super View - removeFromSuperview
it again (in case of swapping views) you required to retain it before calling
Core Java Doubts - Java Beginners
; Hi Friend, 1) class Swapping { public static void main(String[] args... - num2; num1 = num1 - num2; System.out.println("After swapping, num1= " + num1
Working with java Collections class
); System.out.println("List after swapping : " + list); // Replace... swapping : [replaced, replaced, girish, vineet, amit] fill all 'mahendra' in list
What is D2D?
sort of tape. D2D including SATA RAID also provides hot swapping. So D2D has
Java Script With Links and Images
that need to be edited to create JavaScript image swapping.  The JavaScript
10 Unusual Technologies to Come in a Big Way
to wearable electronics and internet ready garments to paying bills by swapping... do all your monetary transactions by just swapping your cell phone against... your cell phone instead of punching or swapping your cards. In any case if once
What is Android Technology?
through real-world action based movements like tapping, swapping, pinching, finger
Sitemap Java Script Tutorial
with JavaScript | Dynamically swapping the images with JavaScript | JavaScript
JavaScript - JavaScript Tutorial
; Dynamically swapping the images with JavaScript In this lesson you
JavaScript - JavaScript Tutorial
; Dynamically swapping the images with JavaScript In this lesson you
Odd Even Transposition Sort In Java
is based on the Bubble Sort technique of comparing two numbers and swapping
Java 5 - "final" is not final anymore - Java Tutorials
final fields at runtime using either class swapping or reflection... was now checked at runtime, so we could not use the class swapping trick
Android 4.3 Jelly Bean - What's new in Android 4.3 Jelly Bean?
fingers smoothly swapping over the keyboard. With more powerful predictive text
Java Programming: Section 8.4
// by swapping it with the number that is currently
EJB, Enterprise java bean, EJB Intoduction- Enterprise Java Beans (EJB) - An Introduction
such as instance swapping, resource pooling, and activation may
JavaScript - JavaScript Tutorial
swapping the images with JavaScript In this lesson you will learn how
Beginners Java Tutorial
.    Swapping of two numbers This Java programming tutorial... numbers. Swapping is used where  you want to interchange the values
Java Programming: Solution to Programming Exercise
"); quitItem.setAccelerator( KeyStroke.getKeyStroke("ctrl Q... // by swapping OSI with undoBuffer. Image temp = OSI
Ajax Framework
, supporting hot swapping of code and debugging. Web mode: This application is run as pure
Advertisements
 

 

 

DMCA.com