ANSWER:-
OPTION (d) the program display 10 20 30 40 50 60
import java.util.*;
class Test
{
public static void main (String[] args) throws
java.lang.Exception
{
PriorityQueue<Integer>queue=new
PriorityQueue<Integer>(
Arrays.asList(60,10,50,30,40,20));
while(!queue.isEmpty())
System.out.print(queue.poll()+"
");
}
}
// OUTPUT
(1) (5 points) What does the following codes display? import java.util.; public class Test public static...
What is output 1 in the code below? import java.util."; public class StackDemo { public static void main(String [] args) { Stack<Integer> intStack = new Stack<>(); Stack<Integer> tempStack = new Stack<>(); intStack.push(18); intStack.push(21); intStack.push(25); tempStack = intStack; while (!tempStack.empty() { System.out.print(tempStack.peek()+"");//output 1 tempStack.pop(); 3 System.out.println(); System.out.println(intStack.peek()); //output 2 25 18 21 • 25 21 18
Given 5. import java.util. 6. public class Sortof 7. public static void main(Stringl args) [ 8. ArrayList Integer> anew ArrayList Integer 0 9. a.add(1); а.add(5); a.add(3); 11. Collections.sort(a) 12. a.add(2); 13. Collections.reverse(a) 14. System.out.printin (a) 15 16 What is the result? B. 12, 1, 3, 5] C. 12, 5, 3, 1] E. [1, 3, 5, 2 F. Compilation fails G. An exception is thrown at runtime Given 5. import java.util. 6. public class Sortof 7. public static void main(Stringl args)...
# Java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a button and place it in the scene Button btOK = new Button("OK"); btOK.setOnAction(e -> System.out.println("OK 1")); btOK.setOnAction(e -> System.out.println("OK 2")); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage...
Provide comments for this code explaining what each line of code does import java.util.*; public class Chpt8_Project { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int [][]courses=new int [10][2]; for(int i=0;i<10;i++) { while(true) { System.out.print("Enter classes and graduation year for student "+(i+1)+":"); courses[i][0]=sc.nextInt(); courses[i][1]=sc.nextInt(); if(courses[i][0]>=1...
I need a java flowchart for the following code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter the input size: "); int n=sc.nextInt(); int arr[]=new int[n]; System.out.print("Enter the sequence: "); for(int i=0;i<n;i++) arr[i]=sc.nextInt(); if(isConsecutiveFour(arr)) { System.out.print("yes the array contain consecutive number:"); for(int i=0;i<n;i++) System.out.print(arr[i]+" "); ...
1: import java.util.*; 2: class Test 3: { 4: public static void main(String[] args) 5: { 6: ArrayList<Object> list = new ArrayList<Object>(); 7: list.add("First Element"); 8: list.add(new Integer(12)); 9: String str = (String) list.get(0); 10: String str2 = (String)list.get(1); 11: } 12: } There is a run time error on which line number? A) Line 9 B) Line 7 C) No errors D) Line 8 E) Line 10 in Java
What is the output of the following question? import java.io.IOException; import java.util. EmptyStackException: public class newclass public static void main(String[] args) try System.out.printf("%d", 1); throw (new Exception()); catch (IOException e) System.out.printf("%d", 2); catch(EmptyStackException e) System.out.printf("%d", 3); catch(Exception e) System.out.printf("%d", 4); } finally System.out.printf("%d", 5); Q3) (15 points) a.Write a JAVA program that reads an arra JAVA program that reads an array from input file and invo Sort and Max ,that sorts the elements of the array and s the elements...
What is the output of the following codes? Line1: public class ArrayLength { Line2: public static void main(String args[]) { Line 3: int a[] = {45, 44, 39, 48, 37); Line 4: System.out.print(a.length()); Line5: Line 6: } w Compiling error Oo 05 04
7. Consider the following recursive function: package javaapplication293; public class JavaApplication293 public static void main Stringl args) recFun(7) public static void recFun int u) if (-= 1 ) System.out. print("Stop! "); else System.out.print("Go "); recFun(u-1);
What is the output of the following code? public class Test { pub be static void main(String() args) { Object o 1 -new Object(); Object o2 = new Object(); System out.print((o1 = o2) + "" + (o1 equals(o2))); } } A. false false B. true true C. false true D. true false Analyze the following code. //Program 1: public class Test { public static void main(String[] args) { Object circle 1 = new Circle(); Object circle2 = new Circle(); System...