We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
for(int i = 0; i < n; i++){
a[i]=scan.nextInt();
}
This piece of code takes input it doesn't print in order for something to be printed we need to use System.out. Therefore this piece of code only accepts input.
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
This piece of code displays each element one by one as the value of i increases. Therefore it is only this loop that prints the values and hence only one loop displays the values.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Java 1D Array
You are viewing a single comment's thread. Return to all comments →
for(int i = 0; i < n; i++){ a[i]=scan.nextInt(); } This piece of code takes input it doesn't print in order for something to be printed we need to use System.out. Therefore this piece of code only accepts input.
for (int i = 0; i < a.length; i++) { System.out.println(a[i]); } This piece of code displays each element one by one as the value of i increases. Therefore it is only this loop that prints the values and hence only one loop displays the values.