Results 1 to 4 of 4
  1. #1
    dannyboy is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default How to do these problems and check if I'm doing it right?

    I have been learning java on my spare time and decided to do some problems I found online. I have no idea if what I am doing is right however and for some I am not sure how to do or what the code should look like. Here are a few problems I am trying to do.

    Write a program that creates an array of Strings of your top three favorite
    movies and an array of Strings of your top three favorite songs. Then use a for loop to
    print out your three favorite movies on separate lines and a while loop to print out
    your three favorite songs all on the same line, separated by commas. Leave two
    blank lines between the movies and the songs.

    This is what I did so far.

    public class Problem1
    {
    public static void main (String[] args)
    {
    String[] arrayNameHere = new String[2];
    arrayNameHere[0] = "movie";
    for (int counter=1;counter<=1;counter++){
    System.out.println("The Dark Knight");
    System.out.println("Godfather");
    System.out.println("Lion King");
    }
    System.out.println();
    System.out.println();
    arrayNameHere[0] = "song";
    int counter=0;
    while (counter<1){
    System.out.println ("My favorite songs are Gentlemen, Gangam Style, and Crazy Train.");
    counter++;
    }
    }
    }

    If possible post a revised code for this if there are any mistakes.

    Another problem I'm doing:
    Write a program that creates an array that can hold 50 integer values. Using a
    for loop and Math.random(), fill the array with random integer values between 0 and
    100. Use a separate for loop print each of the numbers in the array with a single space
    between each number.
    Note: When using a for loop with arrays, use the variable name “index” as the
    counter in the loop as shown below:
    for( int index = 0, index < myArray.length; index++ )

    And the last problem I am doing:

    Write a program that creates an array that can hold 10 integer values. Using a
    for loop and Math.random(), fill the array with random integer values between 0 and
    100 that can either be positive or negative. Use a separate while
    loop to print each of the numbers in the array with a single space between each
    number. The program should then print out the number of positive integers in the
    array.

    For these two programs I am wondering how the codes would look like. Thank you to anyone who answers my post.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,260
    Rep Power
    6

    Default Re: How to do these problems and check if I'm doing it right?

    You're not asking a question that can be answered here. Take it one step at a time, that first program for which you already have code. What are you having trouble with specifically?

    I have no idea if what I am doing is right however
    For now the answer to that is very simple: the application does what you expect it to do. You will become more strict later on in your learning process when you will start to focus on clean code; first you need to learn about classes and objects before you can go that far.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    dannyboy is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: How to do these problems and check if I'm doing it right?

    Quote Originally Posted by gimbal2 View Post
    You're not asking a question that can be answered here. Take it one step at a time, that first program for which you already have code. What are you having trouble with specifically?



    For now the answer to that is very simple: the application does what you expect it to do. You will become more strict later on in your learning process when you will start to focus on clean code; first you need to learn about classes and objects before you can go that far.
    I was wondering if the code was doing what the problem asked me to do exactly. Is there something in the instructions that I did not do right or am missing?

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,260
    Rep Power
    6

    Default Re: How to do these problems and check if I'm doing it right?

    ... well run it and see for yourself :s
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Check my answers for a couple of problems
    By LuluMM in forum New To Java
    Replies: 1
    Last Post: 06-04-2012, 02:39 PM
  2. check this out
    By RajeshReddy in forum New To Java
    Replies: 10
    Last Post: 07-25-2011, 01:28 PM
  3. Can someone check this over?
    By Phyxed in forum New To Java
    Replies: 2
    Last Post: 03-29-2011, 10:07 AM
  4. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 12:12 PM
  5. Don't know what to check for
    By Chasingxsuns in forum New To Java
    Replies: 8
    Last Post: 08-26-2009, 06:59 AM

Posting Permissions

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