PRGM::::4 import java.util.Scanner; import java.util.Arrays; import java.util.Random; public class QuickSortComplexity { static final int MAX = 10005; static int[] a = new int[MAX]; public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter Max array size: "); int n = input.nextInt(); Random random = new Random(); System.out.println("Enter the array elements: "); for (int i = 0; i < n; i++) //a[i] = input.nextInt(); // for keyboard entry a[i] = random.nextInt(1000); // generate // random numbers – uniform distribution a = Arrays.copyOf(a, n); // keep only non zero elements Arrays.sort(a); // for worst-case time complexity System.out.println("Input Array:"); for (int i = 0; i < n; i++) System.out.print(a[i] + " "); // set start time long startTime = System.nanoTime(); QuickSortAlgorithm(0, n - 1); long stopTime = System.nanoTime(); long elapsedTime = stopTime - startTime; System.out....
Posts
Showing posts from July, 2022
- Get link
- X
- Other Apps
PRGM::::2B import java.util.Scanner; import java.util.StringTokenizer; public class Customer { public static void main(String[] args) { String name; Scanner scan = new Scanner(System.in); System.out.println("Enter Name and Date_of_Birth in the format <Name,DD/MM/YYYY>"); name = scan.next(); // create stringTokenizer with delimiter "/" StringTokenizer st = new StringTokenizer(name, ",/"); // Count the number of tokens int count = st.countTokens(); // Print one token at a time and induce new delimiter "," for (int i = 1; i <= count && st.hasMoreTokens(); i++) { System.out.print(st.nextToken()); if (i < count) System.out.print(","); } } }
- Get link
- X
- Other Apps
PRGM::2A import java.util.Scanner; class Staff { String StaffID, Name, Phone, Salary; Scanner input = new Scanner(System.in); void read() { System.out.println("Enter StaffID"); StaffID = input.nextLine(); System.out.println("Enter Name"); Name = input.nextLine(); System.out.println("Enter Phone"); Phone = input.nextLine(); System.out.println("Enter Salary"); Salary = input.nextLine(); } void display() { System.out.format("%-15s", "STAFFID: "); System.out.format("%-15s", StaffID); System.out.println(); System.out.format("%-15s", "NAME: "); System.out.format("%-15s", Name); System.out.println(); System.out.format("%-15s", "PHONE:"); System.out.format("%-15s", Phone); System.out.println(); System.out.format("%-15s", "SALARY:"); System.out.format("%-15s", Salary); System.out.println(); } } class Teaching extends Staff { Str...
- Get link
- X
- Other Apps
PRGM:::1B import java.util.*; class arrayStack { int arr[]; int top, max; arrayStack(int n) { max = n; arr = new int[max]; top = -1; } void push(int i) { if (top == max - 1) System.out.println("Stack Overflow"); else arr[++top] = i; } void pop() { if (top == -1) { System.out.println("Stack Underflow"); } else { int element = arr[top--]; System.out.println("Popped Element: " + element); } } void display() { System.out.print("\nStack = "); if (top == -1) { System.out.print("Empty\n"); return; } for (int i = top; i >= 0; i--) { System.out.print(arr[i] + " "); System.out.println(); } } class Stack { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter Size of Integer Stack "); int n = scan.nextInt(); boolean done = false; arrayStack stk = new arrayStack(n); do { Sy...
- Get link
- X
- Other Apps
PRGM:::;1A import java.util.Scanner; class Student { String USN, Name, Branch, Phone; Scanner input = new Scanner(System.in); void read() { System.out.println("Enter Student Details"); System.out.println("Enter USN"); USN = input.nextLine(); System.out.println("Enter Name"); Name = input.nextLine(); System.out.println("Enter Branch"); Branch = input.nextLine(); System.out.println("Enter Phone"); Phone = input.nextLine(); } void display() { System.out.format("%-20s %-20s %-20s %-20s", USN, Name, Branch, Phone); } } class studentdetails { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter number of student details to be created"); int number = input.nextInt(); Student s[] = new Student[number]; // Read student details into array of student objects for (int i = 0; i < number; i++) { s[i] = new Student(); s[i].read(); } // Display student information ...