C
class Test {
public static void main ( String args []) {
int arr [ 2 ];
System . out . println ( arr [ 0 ]);
System . out . println ( arr [ 1 ]);
}
}
garbage value
garbage value
Output of following Java program?
Java
import java.util.Arrays ;
class Test
{
public static void main ( String [] args )
{
int arr1 [] = { 1 , 2 , 3 };
int arr2 [] = { 1 , 2 , 3 };
if ( Arrays . equals ( arr1 , arr2 ))
System . out . println ( "Same" );
else
System . out . println ( "Not same" );
}
}
Output of following Java program?
C
class Test
{
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" );
}
}
Java
class Test {
public static void main ( String args [] ) {
int arr [] = new int [ 2 ] ;
System . out . println ( arr [ 0 ] );
System . out . println ( arr [ 1 ] );
}
}
garbage value garbage value
Java
class Test
{
public static void main ( String [] args )
{
int arr1 [] = { 1 , 2 , 3 };
int arr2 [] = { 1 , 2 , 3 };
if ( arr1 . equals ( arr2 ))
System . out . println ( "Same" );
else
System . out . println ( "Not same" );
}
}
Predict the output?
Java
// file name: Main.java
public class Main {
public static void main ( String args [] ) {
int arr [] = { 10 , 20 , 30 , 40 , 50 };
for ( int i = 0 ; i < arr . length ; i ++ )
{
System . out . print ( " " + arr [ i ] );
}
}
}
Which of the following is FALSE about arrays in Java?
A java array is always an object
Length of array can be changed after creation of array
Arrays in Java are always allocated on heap
C
public class Main {
public static void main ( String args []) {
int arr [][] = new int [ 4 ][];
arr [ 0 ] = new int [ 1 ];
arr [ 1 ] = new int [ 2 ];
arr [ 2 ] = new int [ 3 ];
arr [ 3 ] = new int [ 4 ];
int i , j , k = 0 ;
for ( i = 0 ; i < 4 ; i ++ ) {
for ( j = 0 ; j < i + 1 ; j ++ ) {
arr [ i ][ j ] = k ;
k ++ ;
}
}
for ( i = 0 ; i < 4 ; i ++ ) {
for ( j = 0 ; j < i + 1 ; j ++ ) {
System . out . print ( " " + arr [ i ][ j ]);
k ++ ;
}
System . out . println ();
}
}
}
Master JAVA and also get 90% fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.
After successfully processing refunds worth over INR 5 Cr, GeeksforGeeks is back with the Three 90 challenge and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!
There are 8 questions to complete.
Take a part in the ongoing discussion View All Discussion