| | |
array problem
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2007
Posts: 30
Reputation:
Solved Threads: 0
wah,,, my only prob here is i dont know how to read the inputted value and store it to become an array..
is this correct? bufferedreader to array? this is the code...
for(int a=0;a<5;a++)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Number : ");
str=br.readLine();
value[a]=Integer.parseInt(str);
}
is this correct? bufferedreader to array? this is the code...
for(int a=0;a<5;a++)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Number : ");
str=br.readLine();
value[a]=Integer.parseInt(str);
}
•
•
Join Date: Sep 2007
Posts: 30
Reputation:
Solved Threads: 0
peep.. my only problem now is counting the occurence...
enter number: 2
enter number: 222
enter number: 2
enter number: 222
enter number: 22
number to be searched is: 2
occurence: 10
but my occurence is showing only 2! it should be 10!
take a look at my code
enter number: 2
enter number: 222
enter number: 2
enter number: 222
enter number: 22
number to be searched is: 2
occurence: 10
but my occurence is showing only 2! it should be 10!
take a look at my code
•
•
•
•
import java.io.*;
public class MP2
{
public static void main(String[] args) throws IOException
{
int value[]=new int[5];
int sear=0;
int d=0,c,a;
int high=0, low=0;
String str;
for(a=0;a<5;a++)
{
BufferedReader data=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Number : ");
str=data.readLine();
value[a]=Integer.parseInt(str);
}
BufferedReader data=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Input number to be search: ");
str=data.readLine();
sear=Integer.parseInt(str);
for(c=0;c<5;c++)
{
if(sear==value[c])
d++;
}
System.out.print("Occurence is "+d);
}
}
because 2 != 222 or 22. If you really need to match each digit, then you need to parse each digit of the number as an Integer, rather than the entire String, of course. Try to work something in, in between the readLine and the parseInt and then, if it still doesn't work, post that modified code and clearly explain the problem, with all error/compiler messages (if any).
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Array problem (Java)
- Array problem (C++)
- Array problem (C#)
- Is there a simplest way to work this array problem? (C++)
- class array problem! (C++)
- C++ help with student array problem (C++)
- i have problem with array plz help (Java)
- Large Array Problem (PHP)
Other Threads in the Java Forum
- Previous Thread: Random Numbers on button
- Next Thread: is it possible to change the button design ?
Views: 1335 | Replies: 14
| Thread Tools | Search this Thread |
Tag cloud for Java
add android api apple applet application arguments array arrays automation binary bluetooth chat chooser class classes client code component converter database detection digit draw eclipse equation error event exception file fractal functiontesting game givemetehcodez graphics gui health helpwithhomework html hyper ide idea image input int integer j2me java javame javaprojects jmf jni jpanel julia linux list loop main map method methods mobile myregfun netbeans newbie nonstatic number object oracle os pattern pearl print problem program programming project recursion scanner screen scrollbar server set size sms socket sort spamblocker sql sqlserver string superclass swing test thread threads time transfer tree windows




bufferedReader)

