Write a java program to swap two numbers with output using third variable by using comment lines plz don't post anything if u don't know... if you post it ur answer will be reported.. ​

Computer Science Secondary School in Computer Science 1 year ago

  6   0   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

ogram using Third Variable:ackage com.company; import java.util.SCANNER; public class main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        System.out.println("Enter 1st number: ");        INT N = sc.nextInt();        System.out.println("Enter 2nd number: ");        int n2 = sc.nextInt();        int n3;        n3 = n;        n = n2;        n2 = n3;        System.out.println("After swapping 1st number is: "+n);        System.out.println("After swapping 2nd number is: "+n2);    } }Your program without using Third Variable:package com.company;  import java.util.Scanner; public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner (System.in);        System.out.println("Enter Number 1:");        int a = sc.nextInt();        System.out.println("Enter Number 2:");        int b = sc.nextInt();        if (a!=b){            a = a+b;            b = a-b;            a = a-b;        }        System.out.println("Numbers after swapping");        System.out.println("1st Number = "+a+"    2nd Number = "+b);    } } I was not able to understand what you means by using COMMENT lines so I gave two programs.

Posted on 12 Aug 2024, this text provides information on Computer Science related to Secondary School in Computer Science. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Tuteehub forum answer Answers

Post Answer

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.