Biodata
Biodata
Biodata
import java.util.Scanner;
if (term <= 1) {
generalInterestRate = 7.5;
seniorCitizenInterestRate = 8.0;
} else if (term <= 2) {
generalInterestRate = 8.5;
seniorCitizenInterestRate = 9.0;
} else if (term <= 3) {
generalInterestRate = 9.5;
seniorCitizenInterestRate = 10.0;
} else {
generalInterestRate = 10.0;
seniorCitizenInterestRate = 11.0;
}
import java.util.Scanner;
int charges = 0;
if (bookingType == 'O'){
// calculate charges for ordinary booking
if (weight <= 100) {
charges = 80;
} else if (weight <= 500) {
charges = 150;
} else if (weight <= 1000) {
charges = 210;
} else {
charges = 250;
}
}else if(bookingType == 'E'){
// Calculate charges for express booking
if (weight <= 100) {
charges = 100;
} else if (weight <= 500) {
charges = 250;
} else if (weight <= 1000) {
charges = 300;
} else {
charges = 200;
}
} else {
System.out.println("Invalid type");
System.exit(0);
}
import java.util.Scanner;
System.out.println("Menu:");
System.out.println("'c' to calculate Area of a Circle");
System.out.println("'s' to calculate Area of a Square");
System.out.println("'r' to calculate Area of a Rectangle");
System.out.print("Enter your choice (c/s/r): ");
char choice = scanner.next().charAt(0);
switch (choice) {
case 'c':
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = Math.PI * radius * radius;
System.out.println("Area of the circle: " + area);
break;
case 's':
System.out.print("Enter the side length of the square: ");
double side = scanner.nextDouble();
double area = side * side;
System.out.println("Area of the square: " + area);
break;
case 'r':
System.out.print("Enter the length of the rectangle: ");
double length = scanner.nextDouble();
System.out.print("Enter the breadth of the rectangle: ");
double breadth = scanner.nextDouble();
double area = length * breadth;
System.out.println("Area of the rectangle: " + area);
break;
default:
System.out.println("Invalid choice");
}
}
}
import java.util.Scanner;
import java.util.Scanner;
switch (choice) {
case 1:
int n = 10;
int firstTerm = 0, secondTerm = 1;
while (number != 0) {
int digit = number % 10;
sum += digit;
number /= 10;
}
import java.util.Scanner;
int left = 0;
int right = n - 1;
boolean found = false;
if (arr[mid] == target) {
System.out.println("Element found at index " + mid);
found = true;
break;
}
import java.util.Scanner;
if (!found) {
System.out.println("Element not found in the array.");
}
}
}
Variable Description Table
Variable Data Type Description
scanner Scanner Scanner object for input.
n int Number of elements in the array.
arr int[] Sorted array of integers in which the search is performed.
left int Left index of the search range.
right int Right index of the search range.
target int Element to search for within the array.
mid int Middle index of the search range.
found boolean Flag to indicate if the target element is found.
Question 8
Write a program to implement the selection sort algorithm to sort an array in
ascending order.
import java.util.Scanner;
System.out.println("Sorted array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}
Variable Description Table
Variable Data Type Description
scanner Scanner Scanner object for input.
n int Number of elements in the array.
arr int[] Array of integers to be sorted.
i int Loop variable for outer loop (selection sort).
j int Loop variable for inner loop (selection sort).
minIndex int Index of the minimum element in the unsorted part.
temp int Temporary variable for swapping elements.
Question 9
Write a program to implement the bubble sort algorithm to sort an array in
ascending order.
import java.util.Scanner;
System.out.println("Sorted array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}
Variable Description Table
Variable Data Type Description
scanner Scanner Scanner object for input.
n int Number of elements in the array.
arr int[] Array of integers to be sorted.
i int Loop variable for the outer loop (bubble sort).
j int Loop variable for the inner loop (bubble sort).
temp int Temporary variable for swapping elements.
Question 10
Write a program to print the sum of diagonals of double dimensional array.
import java.util.Scanner;
int leftSum = 0;
int rightSum = 0;
import java.util.Scanner;
Up to ₹2,50,000 No tax
import java.util.Scanner;
import java.util.Scanner;