sorting - Runtime error. Java. Create a class, Sort that displays four integer numbers in increasing order -


i new in programming, 1 month. should create class, sort displays 4 integer numbers in increasing order. learned here. unfortunately, program doesn't run, when compiling there no error. error message looks this:

stderr exception in thread "main" java.util.nosuchelementexception

at java.util.scanner.throwfor(scanner.java:907)     @ java.util.scanner.next(scanner.java:1530)     @ java.util.scanner.nextint(scanner.java:2160)     @ java.util.scanner.nextint(scanner.java:2119)     @ sort.main(main.java:9)          

here program:

import java.util.scanner; class sort {     public static void main (string[] args) {         int a,b,c,d;          scanner keyboard = new scanner(system.in);         system.out.println("please enter 4 numbers: ");         = keyboard.nextint();         b = keyboard.nextint();         c = keyboard.nextint();         d = keyboard.nextint();          if (a>b) {             int temp = a;             = b;             b = temp;;         }         if (b>c) {             int temp = b;             b = c;             c = temp;         }         if (c>d) {             int temp = c;             c = d;             d = temp;         }         if (a>b) {             int temp = a;             = b;             b = temp;         }         if (b>c) {             int temp = b;             b = c;             c = temp;         }         if (a>b) {             int temp = a;             = b;             b = temp;         }         system.out.println("the numbers :" + + " " + b + " " + c + " " + d);     } } 

nosuchelementexception thrown if input exhausted, i.e. nextint() method has no int return. fix can check if scanner has more ints hasnextint() before call nextint(). should rid of error, believe due program not reading input maybe should rewrite input part.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -