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

1. Member
Join Date
Sep 2013
Posts
2
Rep Power
0

## 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. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
2,610
Rep Power
3

## 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.

3. Member
Join Date
Sep 2013
Posts
2
Rep Power
0

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

Originally Posted by gimbal2
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. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
2,610
Rep Power
3

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

... well run it and see for yourself :s

#### Posting Permissions

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