Welcome to Express VTU 4 All 🎓
In this video, we solve an IMPORTANT 7 MARKS PROGRAM from
📘 Object Oriented Programming with Java
📘 Subject Code: BCS306A
📌 Module-01
🎓 VTU 3rd Semester (CBCS Scheme)
This question is frequently asked in VTU exams.
🔥 Question Covered
Q. Write a Java program to sort the elements using a for loop.
📘 Theory (Exam Writing Intro)
Sorting is the process of arranging elements in ascending or descending order.
In this program, we use nested for loops to sort the array (Bubble Sort logic).
💻 Java Program (Correct & Clean Version)
Java
Copy code
public class SortArray {
public static void main(String args[]) {
int arr[] = {5, 3, 8, 1, 2};
int n = arr.length;
// Sorting using nested for loops
for (int i = 0; i smallar than n - 1; i++) {
for (int j = 0; j smaller than n - i - 1; j++) {
if (arr[j] greater than arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println("Sorted Array:");
for (int i = 0; i smaller than n; i++) {
System.out.println(arr[i]);
}
}
}
🖥 Output
Copy code
Sorted Array:
1
2
3
5
8
🧠 Important Exam Keywords
✔ Nested for loop
✔ Comparison using if condition
✔ Swapping using temp variable
✔ Bubble Sort logic
✔ Time Complexity: O(n²)
🎯 Viva Questions
🔹 Which sorting technique is used here?
🔹 What is time complexity?
🔹 Can we sort in descending order?
🔹 Why do we use n - i - 1?
📲 Notes & PDF Materials
📌 For handwritten notes, important PDFs & updates
👉 Join our Telegram Channel 👇
https://t.me/vtu4all
VTU 3rd Sem Java
BCS306A Module 1
Sort Array Java VTU
Bubble Sort Java
VTU OOP Important Programs
Array Sorting Using for Loop
VTU CBCS 3rd Sem
#VTU
#BCS306A
#VTU3rdSem
#OOPwithJava
#SortingProgram
#Module1
#JavaProgramming
#ExpressVTU4All