Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By JosAH

Thread: User Input???

  1. #1
    jonytek is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default User Input???

    Hi again guys. I am struggling with working out how to call for user input. I am up to an exercise where I need to request 3 int from a user and then output them in ascending order.. Im cant seem to figure out how to call for input.

    I assume the the sorting should be done with if else statements?

    Thanks..

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    For requesting inputs, assuming the user will only input ints, you do not need any if statements.

    This should help you get started. If you have further questions, make sure you post the full working/unworking code and any error messages you might get.

    Luck!

  3. #3
    jonytek is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    Thanks that looks like the answer.

    The if else statement is how I will carry out the sorting into ascending order i.e. smallest, medium, largest.

    thanks.

  4. #4
    Zepher is offline Member
    Join Date
    Feb 2011
    Posts
    15
    Rep Power
    0

    Default

    You might try using bubble sort, Bubble Sort - Sorting Algorithm Animations, to sort the three integers. I don't know your level of experience with Java but, if you are using ArrayLists, you could also consider using Collections.sort(ArrayList<Integer>). Good luck

  5. #5
    jonytek is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    I seem to be getting the following error?????

    Could not find the class:Test scanner. program will exit.

    Any suggestions?

    Java Code:
    import java.util.Scanner;
    
    
    public class TopThree {
    	public static void main(String[] args){
    		System.out.println("Input a number");
    		Scanner scanner = new Scanner(System.in);
    		int num1 = scanner.nextInt();
    		
    		System.out.println(num1);
    		
    		
    		
    	}
    	
    }

  6. #6
    jonytek is offline Member
    Join Date
    Feb 2011
    Posts
    38
    Rep Power
    0

    Default

    Thanks Zepher but i think thats a bit above me. ive been using java for around 1 week now... Lol. thanks anyway. Might have a look anyway ;)

  7. #7
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Quote Originally Posted by jonytek View Post
    Could not find the class:Test scanner. program will exit.
    The name of class that you have posted here is TopThree. Which file are you running exactly? What does your console show?
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  8. #8
    ekay90 is offline Member
    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0

    Default Re: User Input???

    The code you have posted above looks good. I would prompt the user to input an integer two more times, num2 and num3. Then to print the largest, I would implement nested if statements as such:

    if (num1 > num2 && num1 > num3) {
    SOP(num1); }

    else if (num2 > num1 && num2 > num3) {
    SOP(num2); }

    else
    SOP(num3);

    //end code

    Hope this works!

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default Re: User Input???

    Don't resurrect an old thread; I'm closing it.

    kind regards,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Need help getting input(first/last name) from user
    By nightrise420 in forum New To Java
    Replies: 11
    Last Post: 09-11-2010, 04:09 AM
  2. User Input
    By brmcdani in forum New To Java
    Replies: 2
    Last Post: 02-05-2010, 02:59 AM
  3. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-16-2010, 12:02 AM
  4. User input- Pop Up Box
    By dedachi in forum AWT / Swing
    Replies: 3
    Last Post: 03-23-2009, 05:47 AM
  5. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •