Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Different Java array program to perform, Exercises of Java Programming

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

2022/2023

Available from 08/15/2023

hemangi-parmar
hemangi-parmar 🇮🇳

2 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
JAVA ARRAY PROGRAMS
Here are some of the most important and easy java array programs
1. Taking input of an array
2. Sum of an array
3. Square of an array
4. Find the largest number from the array
5. Sort an array
6. Find the second largest and third largest number from the
array
7. Find how many names start from vowel in an array
8. Search name in array
9. Swapping last two digits in an array
10.Write a program to find the names which has only 4 letter in
an array
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Different Java array program to perform and more Exercises Java Programming in PDF only on Docsity!

Here are some of the most important and easy java array programs

**1. Taking input of an array

  1. Sum of an array
  2. Square of an array
  3. Find the largest number from the array
  4. Sort an array
  5. Find the second largest and third largest number from the** **array
  6. Find how many names start from vowel in an array
  7. Search name in array
  8. Swapping last two digits in an array 10.Write a program to find the names which has only 4 letter in an array**

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!!!