Asgment 3

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Asgment 3 as PDF for free.

More details

  • Words: 290
  • Pages: 2
1. What is an array? In computer science an array[1] is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage. 2. Wahat is a 2 demensional array? • •



A two-dimensional array is an array in with both rows and columns. In contrast, gave one dimensional array is simply a linear sequence of elements. When we define or use a two-dimensional array, we must supply both the row and column numbers. Two-dimensional arrays are good for modeling flat surfaces, for example, the screen of a computer, the layout of a warehouse, or a map. Capital flat surface has two dimensions, and so a twodimensional array can easily model it. Java has the ability to define and use arrays with dimensions higher than 2. For example, you can define an array with three dimensions to model physical space, or for dimensions to model physical space with a time dimension. Higher dimensional arrays are common in some applications, such as engineering and physics. However, most applications that use arrays only need one or two-dimensional arrays.

3. why are arrays easier to use than a bunch of related variables? 4.

import java.io.*; class one_Int_array{ public static void main(String args[]) throws IOException{ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String str; int marks[ ] = new int[6];

int sum; //Accepting the marks for(int i=0; i<5; i++){ System.out.print("Enter mark" +(i+1)+":"); str = stdin.readLine(); marks[i] = Integer.parseInt(str); } //Displaying the array for(int i=0; i<5; i++){ System.out.println("Marks" +(i+1)+ ":" +marks[i]); } System.out.println("================="); sum = marks[0] + marks[1] + marks[2] + marks[3] + marks[4]; System.out.println("Sum Of All Marks :" + sum); } }

Related Documents

Asgment 3
November 2019 5
Asgment Agama.docx
November 2019 15
Asgment Elektrik
June 2020 18
3-3-3
December 2019 138