0% found this document useful (0 votes)
94 views

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)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

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)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// 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<a.length; ++x){
a[x] = integer.pareseint(args[x]);
b[x] = a[x] * a[x];
system.out.prinln(b[x]);

}
}
}

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

import java.io.*;

public class array2{

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


inputstreamreader isr = new inputstreamreader(system.in);
bufferedreader br = new bufferedreader(isr);
int[] a = new int[5];
int[] b = new int[5];
string s;
for(int x=0; x<a.length;++x){
system.out.print("enter" + (x+1) + "number: ");
s = br.readline();
a[x] = integer.parseint(s);
}
system.out.println();

for(int x=0;x<a.length;++x){
b[x] = a[x] * a[x];
system.out.println(b[x]);
}
}
}

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

import java.io.*;

public class array3{

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


bufferedreader br = new bufferedreader(new inputstreamreader(system.in));
int[] a = new int[5];
int[] b = new int[5];
string s;
for(int x=0; x<a.length;++x){
system.out.print("enter " + (x+1) + " number: ");
a [x] = integer.parseint(br.readline());
}
system.out.println();

for(int x=0;x<a.length;++x){
b[x] = a[x] * a[x];
system.out.println(b[x]);
}
}
}

You might also like