Results 1 to 7 of 7
  1. #1
    dekelm12 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default 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 array - a.
    The code will define a new array - b which is made of the array a in the power of 2.
    The code will define an array - c, which is made of the product of the number in array - a with the numbers in array - b in a correspondence way.
    The code will output in the first row the numbers of array - a.
    In the second row, the numbers of array - b will be outputted.
    In the third row, the numbers of array - c will be outputted.

    That's it Thanks!

    Java Code:
    import java.util.Scanner;
    public class daf167
    {
      public static void main(String[]args)
      {
        Scanner in= new Scanner(System.in);
        int[] a= int[10];
        int[] b= int[10];
        int[] c= 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?
    Last edited by dekelm12; 12-31-2010 at 01:03 PM.

  2. #2
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    “Alignment”, do you mean array?
    Don't you have any book to read, this is rather basic stuff?
    We can't just do your assignment for you, post the solution though should have worked, and maybe we can help you.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  3. #3
    dekelm12 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Hibernate View Post
    “Alignment”, do you mean array?
    Don't you have any book to read, this is rather basic stuff?
    We can't just do your assignment for you, post the solution though should have worked, and maybe we can help you.
    Well English isn't my mother language, so I guess it's array.
    Anyways, I need the solution. Will someone help me with that?

  4. #4
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    Well English isn't my mother language, so I guess it's array.
    Anyways, I need the solution. Will someone help me with that?
    Many of us mother language also isn't English. That's not problem.
    The real problem is, you asking us to do your assignment. Don't you think, you should at least try and show your effort. We are here to help, not solve your entire problem by writing codes.

    Suggestion : Why not Google your question?
    For beginners, there are always lot of books to read.

    -Regards

  5. #5
    dekelm12 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Prajin View Post
    Many of us mother language also isn't English. That's not problem.
    The real problem is, you asking us to do your assignment. Don't you think, you should at least try and show your effort. We are here to help, not solve your entire problem by writing codes.

    Suggestion : Why not Google your question?
    For beginners, there are always lot of books to read.

    -Regards
    How about trying to help me instead of lecturing me in what is wrong and what is right?

  6. #6
    dekelm12 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    public class daf167
    {
      public static void main(String[]args)
      {
        Scanner in= new Scanner(System.in);
        int[] a= int[10];
        int[] b= int[10];
        int[] c= 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.

  7. #7
    dekelm12 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. I need help on solving an exercise from school
    By dekelm12 in forum Java Applets
    Replies: 4
    Last Post: 12-31-2010, 01:23 PM
  2. Solving Collisions in a car game
    By Rectal Exambot in forum Advanced Java
    Replies: 1
    Last Post: 09-29-2010, 03:13 PM
  3. Help Needed in Solving the Following Isuue.
    By raju.i in forum Advanced Java
    Replies: 3
    Last Post: 05-14-2010, 06:01 PM
  4. Solving a Maze
    By bdario1 in forum New To Java
    Replies: 4
    Last Post: 04-14-2010, 01:02 AM
  5. I need help solving this problem.
    By Felicia in forum New To Java
    Replies: 5
    Last Post: 03-04-2010, 09:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •