Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Teach me to program!!

 
Emmanuel Cesar Cailo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...
[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
Pie
Posts: 15435
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Emmanuel Cesar Cailo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15435
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12180
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Emmanuel Cesar Cailo
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic