Assignment Solutions - Java Variables and Data Types PDF
Assignment Solutions - Java Variables and Data Types PDF
Assignment Solutions
Assignment Solutions
Q1 - Take 2 integer values in two variables x and y and print their product.
int x=2;
int y=4;
System.out.print(x*y);
}
}
int x='U';
System.out.print("The ascii value of U is : " + x);
}
}
Q3 - Write a Java program to take the length and breadth of a rectangle and print its area.
int length=6;
int breadth=5;
System.out.println("The length is : "+ length);
System.out.println("The breadth is : "+ breadth);
int area=length*breadth;
System.out.println("The area is : "+area);
}
}
}
}
Q5 - Write a Java program to swap two numbers with the help of a third variable.
int num1=2;
int num2=3;
System.out.println("The first number before swap is :" + num1);
System.out.println("The second number before swap is : " + num2);
int temp; //variable used to swap two numbers
temp=num1;
num1=num2;
num2=temp;
System.out.println("The first number after swap is :" + num1);
System.out.println("The second number after swap is : " + num2);
}
}