Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.6 kB
2
Indexable
Never
# Task 1
import java.util.Scanner;

public class Task1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int number1, number2, temp;
		Scanner obj = new Scanner(System.in);
		
		System.out.print("Number 1: ");
		number1 = obj.nextInt();
		
		System.out.print("Number 2: ");
		number2 = obj.nextInt();
		
		temp = number1;
		number1 = number2;
		number2 = temp;
		
		System.out.println("Result After Swaping");
		System.out.println("Number 1: " + number1);
		System.out.println("Number2 1: " + number2);
 
	}

}


// Task 2
import java.util.Scanner;
public class Task2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int number1, number2;
		Scanner obj = new Scanner(System.in);
		
		System.out.print("Number 1: ");
		number1 = obj.nextInt();
		
		System.out.print("Number 2: ");
		number2 = obj.nextInt();
		
		number1 = number1 + number2;
		number2 = number1 - number2;
		number1 = number1 - number2;
		
		System.out.println("Result After Swaping(without third variable)");
		System.out.println("Number 1: " + number1);
		System.out.println("Number2 1: " + number2);

	}

}


# Task 3

import java.util.Scanner;
public class Task3 {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int number1, number2, temp;
		Scanner obj = new Scanner(System.in);
		
		System.out.print("Number 1: ");
		number1 = obj.nextInt();
		
		System.out.print("Number 2: ");
		number2 = obj.nextInt();	
		 
		temp = number1 - (number2 * -1);
		System.out.println(temp);
	}

}
Leave a Comment