wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Teach me to program!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Teach me to program!!" Watch "Teach me to program!!" New topic
Author

Teach me to program!!

Emmanuel Cesar Cailo
Greenhorn

Joined: Jul 21, 2011
Posts: 6
Hello guys, i'm just new here. can you guys help me??

Here's my problem, i need a code for selection or bubble sort that the user will input a number.. please guys can you help me. i will do my best to help others too.

thanks in advance
Shubham Chhabra
Greenhorn

Joined: Jul 19, 2011
Posts: 8
...
[MG]Edited ready made solution.
To quote from the top of the forum
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

Welcome to the Ranch, Emmanuel!

How much do you already know about programming in Java; can you make a simple program with which the user can enter the numbers that you want to sort? Do you understand selection sort and bubble sort?

Have you already tried to program something for this assignment yourself; if yes, then where exactly do you get stuck with the problem?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Emmanuel Cesar Cailo
Greenhorn

Joined: Jul 21, 2011
Posts: 6
Jesper de Jong wrote:Welcome to the Ranch, Emmanuel!

How much do you already know about programming in Java; can you make a simple program with which the user can enter the numbers that you want to sort? Do you understand selection sort and bubble sort?

Have you already tried to program something for this assignment yourself; if yes, then where exactly do you get stuck with the problem?


i know programming java a little, but im not good at it. so im trying to understand it.. and thank you for welcoming in Coderanch



ok sir that is my problem, forget the selection and bubble sort code im asking about,
can i insert an user input in there?? because i really need it for tomorrow . thanks in advance sir
oh BTW there's no error in that code i just need to erase the int nums[] = {5,....}; so i can insert my on number in CMD
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

One of the easiest ways to ask for input on the command line is by using class java.util.Scanner, like this:

Now, you will want to have the user enter multiple numbers and store them in the array nums. So you'll have to put the code to enter the numbers in a loop, keeping a counter to keep track in which array element you're going to store the last entered number.
Emmanuel Cesar Cailo
Greenhorn

Joined: Jul 21, 2011
Posts: 6
thanks sir, but how can i insert them to my code above?? or i have to create a new code??
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

right now, you have your array hardcoded on line 4. You can replace that line with the code to get the user input.

Jesper's code can be inserted as-is (I think), but that will only get one number from the user. you will need to write a little addition code for the looping and inserting the value into the correct spot in the array.

It shouldn't be too hard - give it a try!!!


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Emmanuel Cesar Cailo
Greenhorn

Joined: Jul 21, 2011
Posts: 6
@fred, thanks for the advice, i will try it again by tomorrow, i need to sleep so i can wake up early for exam tomorrow,



@jes, thank you for you're effort i appreciate it..

sorry guys if i cannot understand the code, i need to harvest more information hehe THANKS AGAIN, and thank PROGRAMMING there's a CODERANCH it really helps for people that have a problem in programming or any related topics.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Teach me to program!!