1.
Take 10 integer inputs from user and store them in an array and print them on
screen.
Answer
import [Link].*;
class Ans{
public static void main(String[] args){
Scanner s = new Scanner([Link]);
int[] z = new int[10];
for(int i = 0;i<[Link];i++){
[Link]("Print the value of z["+i+"]");
z[i] = [Link]();
}
for(int i = 0;i<[Link];i++){
[Link]("The value of z["+i+"] is "+z[i]);
}
}
}
2. Take 10 integer inputs from user and store them in an array. Again ask user to give
a number. Now, tell user whether that number is present in array or not.
3. Take 20 integer inputs from user and print the following:
number of positive numbers
number of negative numbers
number of odd numbers
number of even numbers
number os 0.
Answer:
import [Link].*;
class Ans{
public static void main(String[] args){
Scanner s = new Scanner([Link]);
int[] z = new int[20];
int pos = 0;
int neg = 0;
int odd = 0;
int even = 0;
int zero = 0;
for(int i = 0;i<[Link];i++){
[Link]("Print the value of z["+i+"]");
z[i] = [Link]();
if(z[i]>0){
pos++;
}
else if(z[i]<0){
neg++;
}
else{
zero++;
}
if(z[i]%2==0){
even++;
}
else{
odd++;
}
}
[Link]("Positive : "+pos+"\nNegative : "+neg+"\nZero :
"+zero+"\nodd : "+odd+"\neven : "+even);
}
}
4. Take 10 integer inputs from user and store them in an array. Now, copy all the
elements in an another array but in reverse order.
5. import [Link].*;
6.
7. class Ans{
8. public static void main(String[] args){
9. Scanner s = new Scanner([Link]);
10. int[] a = new int[10];
11. int[] b = new int[10];
12. for(int i =0;i<[Link];i++){
13. [Link]("Enter the value of a["+i+"]");
14. a[i] = [Link]();
15. }
16. int j = 0;
17. for(int i = [Link]-1;i>=0;i--){
18. b[i] = a[j];
19. j++;
20. }
21. for(int i = 0; i< [Link]; i++){
22. [Link]("The value of b["+i+"] is "+b[i]);
23. }
24. }
25. }
5. Write a program to find the sum and product of all elements of an array.
6. Find largest and smallest elements of an array.
import [Link].*;
class Ans{
public static void main(String[] args){
Scanner s = new Scanner([Link]);
int[] a = new int[10];
for(int i =0;i<[Link];i++){
[Link]("Enter the value of a["+i+"]");
a[i] = [Link]();
}
int largest = a[0];
int smallest = a[0];
for(int i = 0;i<[Link];i++){
if(a[i]>largest)
largest = a[i];
if(a[i]<smallest)
smallest = a[i];
}
[Link]("Largest is "+largest+" and smallest is "+smallest);
}
}