0% found this document useful (0 votes)
131 views2 pages

Exercise 2 Arrays

The document contains three Java programs that take user input of integer arrays, square each element, and output the results. The first program takes command line arguments. The second and third programs take input via buffered reader and output streams.

Uploaded by

api-3738474
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views2 pages

Exercise 2 Arrays

The document contains three Java programs that take user input of integer arrays, square each element, and output the results. The first program takes command line arguments. The second and third programs take input via buffered reader and output streams.

Uploaded by

api-3738474
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// name: delos reyes, jose mari luis c.

// student no.: 04-2-94520

-------------------------------------------

public class array{


public static void main(string[] args){
int [] a = new int [5];
int [] b = new int [5];
for (int x=0; x<[Link]; ++x){
a[x] = [Link](args[x]);
b[x] = a[x] * a[x];
[Link](b[x]);

}
}
}

----------------------------------------------------

import [Link].*;

public class array2{

public static void main(string[] args) throws ioexception{


inputstreamreader isr = new inputstreamreader([Link]);
bufferedreader br = new bufferedreader(isr);
int[] a = new int[5];
int[] b = new int[5];
string s;
for(int x=0; x<[Link];++x){
[Link]("enter" + (x+1) + "number: ");
s = [Link]();
a[x] = [Link](s);
}
[Link]();

for(int x=0;x<[Link];++x){
b[x] = a[x] * a[x];
[Link](b[x]);
}
}
}

---------------(part 2)------------------------

import [Link].*;

public class array3{

public static void main(string[] args) throws ioexception{


bufferedreader br = new bufferedreader(new inputstreamreader([Link]));
int[] a = new int[5];
int[] b = new int[5];
string s;
for(int x=0; x<[Link];++x){
[Link]("enter " + (x+1) + " number: ");
a [x] = [Link]([Link]());
}
[Link]();

for(int x=0;x<[Link];++x){
b[x] = a[x] * a[x];
[Link](b[x]);
}
}
}

You might also like