Create an array of Strings, each containing one of the top 10 reasons that users like in
programming with Java as listed below. Prompt a user to enter a number from 1 to 10,
convert the number to an integer, and then use the integer to display one of the
reasons. Save the application file as JavaReason.java
Top 10 reasons:
Free Debugging Software
No destructors
Nice logo
Free SDK
Runs on the web
Reminds me of coffee
No multiple inheritance
Platform compatible
Great support at the Java Website
Everything in Java has a class

Could you guys give me some hints..

String[] strings = { "a", "b" };

Then see the API docs for Scanner (as this seems to be the preferred method for most instructors, although it is not my personal choice) and Integer.parseInt(String) (although with Scanner this part is not necessary).

System.out.println(strings[index]);

With the number the user then adds, and after you've converted it to an int.
Use a switch statement to take appopriate action depending on the user input...

Uhm, in this case, no, simply use that integer to index into the array.

So far I did this, is it Right ??

public class apples
{
public static void main (String[] args)
{

String[] str_array = new String[9]; 
str_array[0] = "Free Debugging Software";
str_array[1] = "No destructors";
str_array[2] = "Nice logo";
str_array[3] = "Free SDK";
str_array[4] = "Runs on the web";
str_array[5] = "Reminds me of coffee";
str_array[6] = "No multiple inheritance";
str_array[7] = "Platform compatible";
str_array[8] = "Great support at the Java Website";

	
System.out.println("Index 0: " + str_array[0]);
System.out.println("Index 1: " + str_array[1]);{
}
}
}

Well, the array creation, yes, that works. Displaying a specific index also works (although you should be using user intput for that index).

What's missing. of course, is the user input (and the use of that input in the prints).

I don't understand why you've called the class "apples", though.

Edit: And what is with that extra pair of braces after the last print?

Thanks Masijade ,
The reason why i call the Class "apples" its because I am playing around with it.. I will change it later ..
Oh btw i manage to use Joption pane.. It need a little tweeking in my code..Plese comment .

import javax.swing.JOptionPane;

public class apples
{
public static void main (String[] args)
{

String[] str_array = new String[9]; 
str_array[0] = "Free Debugging Software";
str_array[1] = "No destructors";
str_array[2] = "Nice logo";
str_array[3] = "Free SDK";
str_array[4] = "Runs on the web";
str_array[5] = "Reminds me of coffee";
str_array[6] = "No multiple inheritance";
str_array[7] = "Platform compatible";
str_array[8] = "Great support at the Java Website";

JOptionPane.showInputDialog(null, "Enter number 1 to 10");
JOptionPane.showMessageDialog(null, "The Reason are " + str_array[0]);
JOptionPane.showMessageDialog(null, "The Reason are " + str_array[1]);



	

}
}

Have you looked at the API docs for Integer yet?

Shouldn't you be saving the result (i.e. the user input) from that input dialog?

Shouldn't you be using that user input in the print statement?

Aren't you suppossed to print only the question at the indicated index (not two questions)?

Thanks Masijade aka Philip J. Fry :P

I did manage to solve the question by import java.util.Scanner;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.