Java Program to Swap two numbers by using division and multiplication.
Input: 650 350
Output: 350 650
import java.io.*; import java.util.*; public class temp { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter any two numbers: "); int a = scan.nextInt(); int b = scan.nextInt(); a = a*b; b = a/b; a = a/b; System.out.println(String.format("%d %d",a,b)); } }
INPUT_1:
Enter any two numbers:
3 2
OUTPUT:
2 3
INPUT_2:
Enter any two numbers:
20 45
OUTPUT:
45 20
INPUT_3:
Enter any two numbers:
100 110
OUTPUT:
110 100
INPUT_4:
Enter any two numbers:
250 110
OUTPUT:
110 250
ILLUSTRATION
Morae Q!
- Convert from binary number to decimal number.
- Swap two numbers by using division and multiplication.
- Compute foot and inches into centimetres.
- Concatenate Strings.
- Convert lowercase letters to uppercase letters.
- Compute the sum of all the digits of N.
- Compute the area of the pentagon.
- Get input using scanner.
- Find the distance between two points (x1,y1) and (x2,y2).
- Finding patterns in a file using frep and egrep .
- Detecting a cycle in a directed graph using Depth First Traversal.
- Topological ordering in a Graph.
- Storing graphs using adjacency list.
- Introduction to graph theory.
- Graph Adjacency Matrix pseudo code.
- Adjacency Matrix for storing graphs.
- Dijkstra’s shortest path algorithm .
- Breadth first search (BFS) Algorithm.
- Find the multiple of given number in the list of integers.
- Finding patterns in files using grep .