I need help on solving an exercise from school
Hi,
I began my journey in Java a few months ago so I'm a beginner.
I learn it in my school.
Anyway I got an assignment that I need help with.
How do I do the following assignment?
Write a code that inputs 10 numbers into a one-dimensional alignment - a.
The code will define a new alignment - b which is made of the alignment a in the power of 2.
The code will define an alignment - c, which is made of the product of the number in alignment - a with the numbers in alignment - b.
The code will output in the first row the numbers of alignment - a.
In the second row, the numbers of alignment - b will be outputted.
In the third row, the numbers of alignment - c will be outputted.
That's it :) Thanks!
Code:
import java.util.Scanner;
public class daf167
{
public static void main(String[]args)
{
Scanner in= new Scanner(System.in);
int[] a=new int[10];
int[] b=new int[10];
int[] c=new int[10];
int i;
for(i=0;i<=9;i++)
{
System.out.println("Enter a number");
a[i]=in.nextInt();
for(i=0;i<=9;i++)
b[i]=a[i]*a[i];
for(i=0;i<=9;i++)
c[i]=a[i]*b[i]
}
System.out.println("The first row - a is" +a[i]);
System.out.println("The second row - b is" +b[i]);
System.out.println("The third row - c is" +c[i]);
}
}
This is what I've done. What's wrong with it? It doesn't work.
By the way, do you have any tips for Java beginners? :)