Arrays In java

Today I learn about array in java and array most useful in programming language to store integers value , character value , float value in simple word we can say Array which store Similar datatypes

Operation In java

  1. Creating

  2. Input

  3. Output

  4. Update

First Program in Arrray

iimport jdk.jfr.Percentage; import java.time.Period; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int Marks[]= new int[50]; Marks[0] = sc.nextInt(); Marks[1] = sc.nextInt(); Marks[2] = sc.nextInt(); int Pe =((Marks[0]+Marks[1]+Marks[2])/3); System.out.println(Pe +"%"); System.out.println(Marks.length); } }

Functions in java

Arrays as Function In Java

public class ArrayasFunction { public static void update(int marks[]){ int sum=0; for ( int i =0; i<marks.length; i++){ sum+= marks[i]; } System.out.println(sum); } public static void main(String[] args) { int marks[] = {97,98,99}; update(marks); for (int i =0; i <marks.length; i++){ System.out.println(marks[i]); } } }

Largest & smallest Value In Java

public class largestValueInArray { public static int greatestarray(int number[]) { int greatest = Integer.MIN_VALUE; for(int i=0; i<number.length; i++){ if (greatest<number[i]){ greatest =number[i]; } } return greatest; } public static int Smallestarray(int number[]) { int Smallest = Integer.MAX_VALUE; for(int i=0; i<number.length; i++){ if (Smallest>number[i]){ Smallest =number[i]; } } return Smallest; } public static void main(String[] args) { int number[] = {10,250,650,45,52,12,25,}; int large =greatestarray(number); int small = Smallestarray(number); System.out.println(large); System.out.println(small); } }

Reverse In Array

import java.util.Scanner; public class ReverseArray { public static void Reverse(int number[]){ int first =0 , last = number.length-1; while (first<last){ int temp = number[last]; number[last] = number[first]; number[first] = temp; first++; last--; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int number[] = {1,2,3,4,5,6,7,8,9,10}; Reverse(number); for (int i =0 ; i<number.length; i++){ System.out.print(number[i]+" "); } } }

0
Subscribe to my newsletter

Read articles from Venkatesh Rapolu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Venkatesh Rapolu
Venkatesh Rapolu