Make a program Minimum of 3 Classes(They have to work) minimum of 6 methods ( al
ID: 652804 • Letter: M
Question
Make a program
Minimum of 3 Classes(They have to work)
minimum of 6 methods ( all working)
Must include: If, for, while, if else arrays, nested statements. Minimum of 4 each (at least 2 arrays.)
if and if else can work together.
2 calls for a class object.
at least two methods containing arguments. example (methodName(int thingHere)
code needs to be working error free and clean. thanks
must have input from a user, example math, diaoluge box, or butttons ect.
Also include at least 1 advanced java function. (example like loading an image or gui interface.
Explanation / Answer
import java.io.*;
class aclass
{
void sq(int a[])
{
int i;
for(i=0;i<5;i++)
{
System.out.println("Square is "+a[i]*a[i]);
}
}
void odd( int a[], int b[], int c[])
{
int i;
for(i=0;i<5;i++)
{
if((a[i]%2) == 0)
{
b[i] = a[i];
}
else
{
c[i] = a[i];
}
}
}
void disp(int b[], int c[])
{
int i;
for(i=0;i<5;i++)
{
System.out.println(b[i]);
}
for(i=0;i<5;i++)
{
System.out.println(c[i]);
}
}
};
class dt_simp
{
public static void main(String args[]) throws IOException
{
int[] a= new int[5];
int [] b = new int[5];
int[] c= new int[5];
int i;
String s1;
aclass o = new aclass();
DataInputStream o1=new DataInputStream(System.in);
for(i=0;i<5;i++)
{
System.out.println("Enter no");
s1=o1.readLine();
a[i]=Integer.parseInt(s1);
}
o.sq(a);
o.odd(a,b,c);
o.disp(b,c);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.