0% found this document useful (0 votes)
9 views

Arrays Practices Question

Uploaded by

Manish Singh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Arrays Practices Question

Uploaded by

Manish Singh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1.

Java Program to find maximum in arr[]

Ans.

public class Find_max_in_Arrays {

public static void main(String[] args) {


int[] x= {10,300,25,399};
int max=x[0];

for(int i=0;i<x.length;i++)
{
if(x[i]>max)
{
max=x[i];
}

}
System.out.println(max);

Q2. java program to sort the arrays

Ans. package com.java;

public class Shorting_Arrays {

public static void main(String[] args) {


int[] x=new int[] {12,5,8,16,58,4};

int temp;
for (int i = 0; i < x.length; i++) {
for (int j = i+1; j < x.length; j++) {

if(x[i]>x[j]) // 12>
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}

}
for (int i = 0; i < x.length; i++) {
System.out.println(x[i]);
}

}
Q3. Java program to Find_the_Max_Arrays and MIN inside given arrays
Ans.package com.java;

public class Find_the_Max_Arrays {

public static void main(String[] args) {


// TODO Auto-generated method stub

int[] x= {10,23,25,48,11};

int a=x[0];
for (int i=0;i<x.length;i++) {
if(x[i]<a)
{
a=x[i];
}

}
System.out.println(a);
}

Q4. Java Program to find duplicate value in given arrays


Ans. package com.java;

public class Find_duplicate_Array {

public static void main(String[] args) {


// TODO Auto-generated method stub

int[] x= {12,35,45,85,45};

//int a=x[0];

for (int i=0;i<x.length;i++) {


for (int j=i+1; j < x.length; j++) {

if(x[i]==x[j])
System.out.println("Arrays Having Duplicate elemenets:
"+x[j]);

Q5. WAP in java to perform copy of arrays inside another arrays


package com.java;

public class Copy_of_one_arrays_inti_another_arrays {

public static void main(String[] args) {


// TODO Auto-generated method stub
int[] x= {10,5,12,23,24};
int[] y=new int[5];

for (int i = 0; i < y.length; i++) {


y[i]=x[i];
}

System.out.print("This is a copy of arrays:" );


for (int i = 0; i < y.length; i++) {
System.out.print(y[i]+",");
}
}

Q6. WAP in java to find the MAX and MIN value in the Given Arrays
package com.java;

public class Max_and_Min_elementOf_arrays {

public static void main(String[] args) {


int[] a=new int[] {122,112,130,110,105,142,135};

int temp;
for (int i = 0; i < a.length; i++) {
for (int j = i+1; j < a.length; j++) {

if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}

for (int i = 0; i < a.length; i++) {


System.out.print(a[i]+",");
}
System.out.println();
System.out.println("The Max value of arrays is: "+a[ a.length-1] +"\
n"+"The Min value of arrays is: "+ a[(a.length)-(a.length)]);

// a.length =7
// a.length=6
}

Q7.

You might also like