NPTEL » Programming In Java Week 3 : Programming Assignment 5 Aug 2022

 

Week 3 : Programming Assignment 5

Due on 2022-08-18, 23:59 IST

Complete the code segment to swap two numbers using call by object reference.



import java.util.Scanner;

class Question {  //Define a class Question with two elements e1 and e2.

    Scanner sc = new Scanner(System.in);

    int e1 = sc.nextInt();  //Read e1

    int e2 = sc.nextInt();  //Read e2

}

public class Question3 {

// Define static method swap()to swap the values of e1 and e2 of class Question.


    public static void swap(Question t)

    {

    int temp = t.e1;

        t.e1 = t.e2;

        t.e2 = temp;

    }

    public static void main(String[] args) {

        //Create an object of class Question

    Question t = new Question ();

        //Call the method swap()

        swap(t);

        System.out.println(t.e1+" "+t.e2);

    }

}






1 comment

  1. Java Course in Noida
    https://aptronsolutions.home.blog/2022/08/01/8-java-frameworks-for-a-cloud-native-world/

    ReplyDelete

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...