Core Java Tutorial

Question :: Write a Scala Program to1. Insert elements and print elements in array.2. print nth element of an array.3. Concatenate two arrays.4. insert elements in a two dimensional array and printing it

Program ::

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

packagecom.ai1tutorial.scala

// import the Array package to get Array methods

import Array._

objectArrayOperations{

def main(args:Array[String]){

// declare an Integer array

vararr=newArray[Integer](3)

//Insert elements into array

for(i<-0toarr.length-1){

arr(i)=i;

}

println("printing the array elements ")

// Print all the array elements

for(x<-arr){

print(x+"\t")

}

// accesing a particular index element

println("\nprinting the 2nd element "+arr(1))

println("printing the range array")

// define array with a range of elements

varrangeArray=range(10,20)

// Print all the array elements

for(x<-rangeArray){

print(x+"\t")

}

println("\nConcatenating two arrays")//optional -- to provide next line after previous print of rangeArray

//Concatenate two arrays

//declare array with predefined values

vararr1=Array(7,8,9)

vararr2=range(10,20)

varconcatArray=concat(arr1,arr2)

// Print all the array elements

for(x<-concatArray){

print(x+"\t")

}

println("\nPrinting matrix elements")//optional -- to provide next line after previous print of rangeArray

4 : Right Click on the File “HelloWorld.scala” and run as Scala Application

Output ::

1

Hello,world!

About the Author

Dear Friends,
I am A.K.M. .This online journal ai1tutorial.com is a humble effort from my side to all students and professionals who want to learn computer science related technologies.I am not a professional blogger and I write posts in this blog only in my leisure time.I may not be 100% perfect in all my posts,but your review comments can surely help me to make it 100% perfect.