Solution :-
public class ArrComp
{
public static void main(String args[])
{
int arr1[] = {1,2,3};
int arr2[] = {1,2,3};
if(arr1 == arr2)
System.out.println("Same");
else
System.out.println("Not Same");
}
}
The output of the code is Not same.
Explanation :-
The output of the above code will be Not same. Although the elements in both the arrays is same i.e 1,2,3 but in this case when we compare both the arrays by using if decision statement i.e if(arr1 = = arr2), this will compare the base address of both the arrays. The arrays(arr1 and arr2) are stored in different memory locations and hence their base address will be different respectively.
Thus when the control of the program checks the condition if(arr1 = = arr2) it will be false and the control jumps to the else block and prints "Not same." Thus the output of the above code is Option b i.e Not same.
What is the output of the following codes? Line1: public class ArrayCompare { Line2: public static...
What is the output of the following codes? Line1: public class ArrayCompare ! Line2: public static void main (String[] args) { Line 3: int arr1[] = {1, 2, 3); Line4: int arr2[] = {1, 2, 3); Line5: if (arri == arr2) Line 6: System.out.println("Same"); Line 7: else Line 8: System.out.println("Not same"); Line9 : Line10: ) } Not same Same
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
What is the output for the following program codes? a) [ 0.5 Mark ] class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); }} class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); }} OUTPUT: b) [ 0.5 Mark ] class Parent { public void getBike(){ System.out.println("Suzuki Bike"); }} class Child extends Parent {...
What is the Java output? Part One: class Driver { public static void main(String[] args) { int a = 5; int b = 3; if (a < b || a * 2 < b) System.out.print(a - b); System.out.print(b + a); } } Part Two: class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a < b) if (a * 2 < b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } }
What is the output of the following code? Explain your answer. public class Test {public static void main (String [] args) {System.out. print((int) 5.6); System.out.println((int) 5.2);}}
What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);
import java.util.Arrays; public class lab { public static void main(String args[]) { int arr[] = {10, 7, 8, 9, 1, 5,6,7}; int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1}; int arr3[] = {1, 3, 5, 3, 2, 6, 20}; quicksort(arr,0,arr.length-1); quicksort(arr2,0,arr2.length-1); quicksort(arr3,0,arr3.length-1); System.out.println(Arrays.toString(arr)); System.out.println(Arrays.toString(arr2)); System.out.println(Arrays.toString(arr3)); } private static int partition(int[] items,int low, int high) { int i=0; int j=0;...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
What will be the output of the following Java code? class Output { public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!c); } } a) 0 b) 1 c) false d) true
public class Test { private static int i =0; private static int j =0; public static void main(String[] args) { int i = 2; int k = 3; { int j =3; System.out.println("i + j is : " + i + j); } k = i + j; System.out.println("K is " + k ); System.out.println("K is " + j); } } why is the output i + j = 23 K =2 K =0 Please explain a step by step...