Java Array Homework Help
Previous
Next
Java Array:
Array is collection same data type with sequential order. It is used to declare and access collection of variables.
Declare arrays:
First we have to specify the data type and follow by the variable name.
Syntax:
Datatype [] variablename;
Example:
Int [] numers;
Creating array:
Using new keyword we can create an array.
Syntax:
Datatype [] variablename= new datatype [ array size];
Example:
Int [] numbers= new int[10];
Example program:
{`public class sampleArray { public static void main(String[] args) { int[] numbers = { 1, 2, 3, 4 } ;; // Print all the array elements for (int i = 0; i < numbers.length; i++) { System.out.println(numbers[i] + " "); } ; // Summing all elements int total = 0; for (int i = 0; i < numbers.length; i++) { total += numbers[i]; } ; System.out.println("Total is " + total); // Finding the largest element int max = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] > max) max = numbers[i]; } ; System.out.println("Max is " + max); } ; } ; `}
Output:
1
2
3
4
Total is 10
Max is 4
Java Tutorials
- Environment setup
- Basic concept
- Object Classes
- Constructors
- OOPS in java
- data abstraction
- Variable Types
- Modifiers
- Operators
- Loop Controls
- Decision Making
- Strings
- Arrays
- Date and Time
- Methods in java
Java sample assignments
Programming Topics
- Ada
- Assembly Language
- AutoCAD
- BASIC
- Computer virus
- C Programming
- Euphoria
- Fortran Homework Help
- Game programming language
- Java Assignment Help
- JavaScript
- Java Servlets Help
- Machine Language
- Matlab
- Pascal
- Perl
- PHP
- Python
- Ruby
- Servlet Life Cycle
- Smalltalk
- SOAP
- Visual Basic
- COBOL
- Lisp
- Logo Help
- Plankalkul Help
- Prolog
- REBOL
- Rexx
- Scheme Help
- TCL
- ToonTalk Help