Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld >> Java Beginner

Pages: 1
Limuh
stranger


Reged: 08/19/08
Posts: 1
Array
      #181980 - 08/19/08 09:46 PM

Hello,
i am taking a hard time to do this thing into coding please help this is the problem.
if the user chooses to do searching, the program will create an array consisting of 20 randomly generated integers between 1 and 100. The user then provide a search key between 1 and 100. the program should then display the contents of the array created and inform the user if the search key is in the array or not. if it is in the array, the index where it is located should also be displayed.

sorry im super new to this any help is apreciated..

Thanks!


Post Extras: Print Post   Remind Me!   Notify Moderator  
lance_en
stranger


Reged: 08/20/08
Posts: 2
Re: Array [Re: Limuh]
      #182003 - 08/20/08 04:57 AM

package com.test

import java.util.Random
import java.io.IOException
import java.io.InputStreamReader
import java.io.BufferedReader
public class ArrayTest {
private static Random rand = new Random(100)
private static int[] values = new int[20]


Post Extras: Print Post   Remind Me!   Notify Moderator  
lance_en
stranger


Reged: 08/20/08
Posts: 2
Re: Array [Re: Limuh]
      #182004 - 08/20/08 04:58 AM

public static void main(String[] args) {
try {
System.out.println("Please input a key to search ")
BufferedReader reader=new BufferedReader((new InputStreamReader(System.in)))
int key=Integer.parseInt(reader.readLine())
new ArrayTest().search(key)
} catch (NumberFormatException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}
}


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 3 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 5141

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5