








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
you can't miss this program !!!!! here I have done ten of the most asked array programs in university level exam all the programs are done and has been executed to help you must go through it if you have started arrays in java
Typology: Exercises
1 / 14
This page cannot be seen from the preview
Don't miss anything!
Here are some of the most important and easy java array programs
**1. Taking input of an array
import java.util.*; public class Array { public static void main(String mm[]) { Scanner k=new Scanner(System.in); String data[]=new String[10]; for(int i=0; i<data.length; i++) { System.out.println("enter the name"); data[i]=k.next(); } for(int i=0; i<data.length; i++) { System.out.println("entered elements are as follows: "+data[i]); } } }
sum=data[i]+sum; } System.out.println("the sum of an array is: "+sum); } }
3. Square of an array import java.util.*; public class Arraysquare { public static void main(String rr[]) { Scanner k=new Scanner(System.in); int data[]= new int[10]; for(int i=0; i<data.length; i++) { System.out.println("enter the value of an array: "); data[i]=k.nextInt(); } System.out.println("entered value are as follows"); for(int i=0; i<data.length; i++)
System.out.println("the value you eneterd: " +data[i]); } for(int i=0; i<data.length; i++) { System.out.println("the square of an array :"+data[i]*data[i]); } } }
4. Find the largest number from the array import java.util.*; public class FindLargest { public static void main(String args[]) { Scanner k=new Scanner(System.in); int array[]=new int[10]; for(int i=0; i<array.length; i++) {
Scanner k=new Scanner(System.in); for(int i=0; i<data.length; i++){ System.out.print("enter the number : "); data[i]=k.nextInt(); } for(int i=0; i<data.length; i++) { for(int j=0; j<data.length; j++) { if(data[i]<data[j]) { int temp=data[i]; data[i]=data[j]; data[j]=temp; } } } for (int i:data){ System.out.print(i+" "); } } }
6. Find the second largest and third largest number from the array
import java.util.*; public class secondlargest { public static void main(String args[]) { Scanner k=new Scanner(System.in); int data[]=new int[10]; for(int i=0; i<data.length; i++) { System.out.println("enter the value :"); data[i]=k.nextInt(); } System.out.println("entered values are as follows"); for(int index=0; index<data.length; index++) { System.out.println("value that you entered at index "+index+" : "+data[index]); } int temp; for(int i=0; i<data.length; i++)
public class VowelCount { public static void main(String mm[]) { Scanner k=new Scanner(System.in); String data[]=new String[10]; for(int i=0; i<data.length; i++) { System.out.println("enter the name"); data[i]=k.next(); } int count=0; for(int i=0; i<data.length;i++) { char c=data[i].charAt(0); if( c=='A' || c=='E' || c=='I' || c=='O' || c=='U'|| c=='a'|| c=='e'|| c=='i'|| c=='o'||c=='u') count++; } System.out.println("The numebr of names starting with the vowels are "+count ); }
8. Search name in array import java.util.*; public class Arraysearch { public static void main(String mm[]) { String names[]=new String[3]; String n; Scanner k=new Scanner(System.in); for(int i=0; i<names.length; i++) { System.out.print("enter the name : "); names[i]=k.next(); } System.out.print("enter the name you want to search: "); n=k.next(); boolean check=false; for(int i=0; i<names.length; i++) { if (names[i].equalsIgnoreCase(n)) check=true; }
for(int i=0; i<array.length; i++) { System.out.println("the value you entered is : "+array[i]); } int temp=array[array.length-1]; array[array.length-1]=array[array.length-2]; array[array.length-2]=temp; for(int i=0; i<array.length; i++) { System.out.println("the new value after swapping is : "+array[i]); } } } 10.Write a program to find the names which has only 4 letter in an array import java.util.*; public class VowelFour { public static void main (String args[]) {
String data[]=new String[10]; Scanner k=new Scanner(System.in); for(int i=0; i<data.length; i++) { System.out.println("enter the names : "); data[i]=k.next(); } for(int i=0; i<data.length; i++) { if(data[i].length()==4) System.out.println("the name with 4 letters are : "+data[i]); } } } HOPE THIS HELPS!!!