Where is the problem in this Code

0 Manar A · April 9, 2015
Peace upon you all 


i have this code for a program that take any 5 numbers  
and display the elements except if that number is already inserted before 
 
i did not use java IDE on my computer because it's x32 and could not find a jdk  version 
so i used online interpreter .  i don't know if this the problem or not why the code does not work . 


Sorry i don't know why the previous one did not appear .

and this is what the message i see when i use any online compiler 
(
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Numbers.main(Numbers.java:20)


)





import java.util.Scanner;
// our main class becomes a file but the main method is still found
public class  Numbers
{
public static void main (String[] args)
{
int array[] =new int[5];
Scanner input=new Scanner(System.in);
     
for(int i=0; i<array.length;i++){

          array =input.nextInt();

        for( int dublicate=array[0]; dublicate <array.length; dublicate++) {

          if (array==dublicate)

          {
System.out.print(array[--i]);
            
            System.out.println("-------------"); }
          else

          { System.out.print(array);

 System.out.println("-------------"); }
}
}
    }

 
[/code]

Post a Reply

Replies

Oldest  Newest  Rating
+1 Yaron X · April 10, 2015
Looks as if you didn't paste the entire code in your post.
+1 Nicholas Eason · April 10, 2015
You also dont describe your problem, you just say that it doesn't work.
0 Manar A · April 11, 2015
This my first post Excuse me i make mistakes :D
0 Nicholas Eason · April 13, 2015
{ System.out.print(array);

Line 20 you did that. You can't print a whole array like that :P
0 Manar A · April 14, 2015
alright i fixed it in this form 
System.out.print(array[i]);


but still not working 
0 Nicholas Eason · April 14, 2015

for(int i=0; i<array.length;i++){

array =input.nextInt();




You can't declare an array variable like that either :P You need:

array[x] = input.nextInt();

It wasn't letting me use i for the index in the Array... Probably because it was expecting Italicized text. Replace the x with an i :P
  • 1

Java / Android Development

107,302 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator