Tutorial Questions
Date:24/7/26
1. College is developing a student information system. Write a Java
program to display a student's name, register number, department, year of
study, and college name in a neatly formatted manner.
PROGRAM:
import [Link];
public class tut1 {
public static void main(String[] args) {
Scanner s = new Scanner([Link]);
[Link]("Enter name of student");
String name = [Link]();
[Link]("Enter roll number :");
int roll = [Link]();
[Link]("Enter year of study");
int year = [Link]();
[Link]();
[Link]("Enter department :");
String department = [Link]();
[Link]("Enter college name :");
String college = [Link]();
[Link]("Name is: " + name);
[Link]("Roll Number: " + roll);
[Link]("Year of Study: " + year);
[Link]("Department: " + department);
[Link]("college name is :"+ college);
}
}
OUTPUT:
Enter name of student
Farhathullah
Enter roll number :
2295
Enter year of study
2026
Enter department :
CTECH
Enter college name :
SRMIST
Name is: Farhathullah
Roll Number: 2295
Year of Study: 2026
Department: CTECH
college name is :SRMIST
2. A supermarket cashier needs to calculate the total, difference (discount
comparison), product, quotient, and remainder of the prices of two
products. Write a Java program to perform these arithmetic operations
and display the results.
PROGRAM:
import [Link];
public class tut2 {
public static void main(String[] args) {
Scanner s = new Scanner([Link]);
[Link]("enter price of product 1");
float a = [Link]();
[Link]("enter price of product 2");
float b = [Link]();
float sum = a + b;
float diff = a - b;
float product = a * b;
float quotient = a / b;
float remainder = a % b;
[Link]("sum is: " + sum);
[Link]("difference is: " + diff);
[Link]("product is: " + product);
[Link]("quotient is: " + quotient);
[Link]("remainder is: " + remainder);
[Link]();
}
}
OUTPUT:
enter price of product 1
99
enter price of product 2
89
sum is: 188.0
difference is: 10.0
product is: 8811.0
quotient is: 1.1123595
remainder is: 10.0
3. The Physical Education Department wants to calculate the area of a
rectangular playground before marking it for the annual sports meet.
Write a Java program to calculate the area using the given length and
breadth
PROGRAM:
import [Link];
public class tut3 {
public static void main(String[] args) {
Scanner s = new Scanner([Link]);
[Link]("Enter length");
float length = [Link]();
[Link]("Enter breadth");
float breadth = [Link]();
float area = length * breadth;
[Link]("Area is:" + area);
[Link]();
}
}
OUTPUT:
Enter length
70
Enter breadth
25
Area is:1750.0
4. Two students accidentally exchanged their roll numbers in the attendance
register. Write a Java program to swap the two roll numbers:
● (a) Using a temporary variable.
● (b) Without using a temporary variable.
PROGRAM:
import [Link];
public class tut4 {
public static void main(String[] args) {
Scanner s= new Scanner([Link]);
[Link]("Enter number a");
int a = [Link]();
[Link]("Enter number b");
int b = [Link]();
int temp= a;
a= b;
b = temp;
[Link]("After Swapping: ");
[Link]("a = " + a + ", b = " + b);
OUTPUT:
5. Three students participated in a coding competition. Their scores are
given. Write a Java program to find the student with the highest score.
6. A movie theatre has separate counters for even-numbered and odd-
numbered seat numbers. Write a Java program to determine whether the
given seat number is even or odd.
7. A class teacher wants to identify whether a student has passed the internal
assessment. The passing mark is 50. Write a Java program to accept the
student's marks and display "Pass" if the marks are 50 or above;
otherwise, display "Fail".
8. A company wants to calculate an employee's monthly salary. Write a
Java program to accept the employee's basic salary and allowance, then
calculate and display the total salary.