Programing 2 - Lab 00
Programing 2 - Lab 00
Page 1 of 4
Alexandria National University
Faculty of Computer and Information
Lecturer: Dr. Amr AboHani, Dr. Ahmed Saleh, Dr. Ahmed Moustafa
Course: Programming 2
Lab #: 0
-------------------------------------------------------------------------------------------------------------------------------
Part 2: Students work in Lab.
Question 1. What is the output of the following?
a-
b-
Page 2 of 4
Alexandria National University
Faculty of Computer and Information
Lecturer: Dr. Amr AboHani, Dr. Ahmed Saleh, Dr. Ahmed Moustafa
Course: Programming 2
Lab #: 0
-------------------------------------------------------------------------------------------------------------------------------
Question 2. Write a Java method to find the smallest number among three
numbers.
Test Data:
Input the first number: 25
Input the Second number: 37
Input the third number: 29
Part 3: Homework
Question 1. What is the output of the following
a-
class Test{
static void set (int x){
int y=x+2;
x*=2;
}
public static void main(String[] args) {
{
int x=10,y=11;
set(x);
set(y);
System.out.println("X= "+ x+" ,Y= "+y);
}
}
b-
public class Test1 {
static void func(int x, double y){ System.out.println((x+y/2)); }
static void func(double x, int y) { System.out.println((x-y*2)); }
public static void main(String[] args) {
int a = 2;
double b = 5;
func(a, b);
func(b, a);
Page 3 of 4
Alexandria National University
Faculty of Computer and Information
Lecturer: Dr. Amr AboHani, Dr. Ahmed Saleh, Dr. Ahmed Moustafa
Course: Programming 2
Lab #: 0
-------------------------------------------------------------------------------------------------------------------------------
}
}
c-
class Test{
static void swap1(int x[]){
int temp;
temp=x[0];
x[0]=x[1];
x[1]=temp;
}
public static void main(String[] args) {
int A[]={2,6};
System.out.println("First two element in array before call swap1 are
"+A[0]+","+A[1]);
swap1(A);
System.out.println("First two element in array After call swap1 are
"+A[0]+","+A[1]);
}
}
Page 4 of 4