Romance › Re: Warning!!! Girls Never Date Such A Guy (photo) by realowded(m): 8:40pm On Mar 13, 2015 |
 Iamfrank: Stinginess of d highest order This is not stingyness ooo... The guy wants to ensure both are of the same weight..... |
Politics › Re: FG Reduces Price Of Petrol To 87 Naira Per Litre by realowded(m): 10:19pm On Jan 18, 2015 |
I find this insulting... They think they can ever done anything to make us vote them?... They shud try again.... |
Programming › Re: Java Tutorial For Beginners by realowded(m): 12:32am On Jan 16, 2015 |
nnasino: Methods Methods are used to group a set of statements performing one task. When you write code which you notice keeps repeating itself then you might need to create a method/function to handle that task. Functions can take values called parameters which it will use in its computation. An example of a function is a function that checks if a number is a prime number or not. Functions/methods can return an answer or not. When a function does not return any value it is of type void. Defining a function:
type nameOfMethod(parameter list){ body of method; return avalue; //if type is not void }
If you are not returning any value then type should be void . If you are returning a value then type should be the type of the value you want to return (int, float, double, String etc). Also, if you are returning a value then you must have the return keyword in the body of the method. The parameter list, is a comma separated list of the parameters to be passed to the function. The parameters must have the type and the name by which they will be accessed. An example
int sum(int a, int b){ //This function sums two numbers return a + b; //using the two parameters passed to it. }
The above function takes, two
Getting user input from the user: We haven't discussed classes or objects so far but we will need to use them in our exercises so i'll give crash course on both. A class is simply a framework for creating objects. It contains variables and functions within it which represent properties and behaviours of the objects it will be used to create respectively. For example, a vehicle class is a framework for creating vehicles. It's properties can include speed, colour, size, etc while it's behaviours include move(), stop(), changeOil() etc. So with a single class definition we can create numerous objects each having their own properties. The good thing about objects is that we can use them without knowing how they are implemented. A car can be driven without knowing what engine is in it or how it was built. Objects can also be nested within one another. A steering wheel is a fully developed object with its own components. But it is contained in the vehicle object. The vehicle doesn't need to know anything about how the steering wheel was built/created all it needs to know are what it can be used for and how to use it. We will delve into objects later on but for now we need to use one in our program ( we will be using it regularly).
The Scanner class is a built-in java class for reading input. It can read from files, standard input (user) and other streams. To use these functions we need to create an object of the Scanner class. In java this is done by:
Scanner scannerObject; We have declared the scanner class, but before we can use it we need to initialize it. New Concept: Constructor : A constructor is a function that is used to initialize a newly created object. We'll stop there for now and continue. Just note that the constructor of a class is a function with the same name as the class. Now the Scanner class's constructor takes one parameter which represents where the input comes from. In our case, the input comes from Standard input (keyboard), so the parameter is System.in . So to declare and initialize the Scanner object we have:
Scanner scan = new Scanner(System.in);
This creates an object for us. We also need to import the Scanner class. We do this by putting import java.util.Scanner; at the top of the file. For now ignore all these, we will still treat objects and classes later on. But for now just copy this code into your file. Note: If you use netbeans, set up your key map with the eclipse settings so you can follow with the shortcut keys i will be using to do this, click Tools menu > options, then click the keymap tab and change the netbeans to eclipse, click apply and then ok.
Netbeans will be very helpful when working with objects. Now you have set up your key map. You can use the following: Type Sca and press Ctrl+space, this will bring up a list of all classes matching the what you've typed select the one you require and press enter, in this our case the one in java.util. Doing this will automatically import the class for us. Also, we can type Scanner and declare and initialize the object without importing. The IDE will definitely complain, at this point press Ctrl+shift+O, this imports all missing classes. As we move on, i'll be introducing more function keys for making our work easy.
Now to our challenges: Challenge 1: Write a program which displays the number of prime numbers from zero to a number. Number should be provided by the user. We break the problem into components: - Get number from the user. - check if each number is a prime number. if they are increment the count. - Display the count to the user.
To get input from the user we use the Scanner class -We will be checking many numbers therefore we will need a loop -We will be checking if a number is prime so we will create a function to check
The program therefore goes:
class Primes{ static boolean isPrime(int number){ //isPrime is declared as static, so we can use it within main (main is also static) if(number == 2) return true; for(int i = 2; i < number; i++){ if(number % i == 0) //If the number can be divided by any other number apart from 1 and itself return false; //Then it is not prime } return true; //If not it is prime } public static void main(String[] args){ //type psvm and press tab, netbeans will complete this for you int number = 0; //Variable for holding the maximum number Scanner scan = new Scanner(System.in); System.out.println("Please enter the maximum number" ); //type sout and press tab number = scan.nextInt(); int count = 0; //The number of primes found for(int i = 2; i <= number; i++){ if(isPrime(i)) count++; } System.out.println("The number of primes between 1 and " + number + " is " + count); } }
Please bro, explain each line of codes... |
Programming › Re: Java Tutorial For Beginners by realowded(m): 3:56pm On Jan 10, 2015 |
nnasino: Hello everyone, Back to business. Today, i'll digress a little. I'll be teaching some tips and tricks on how to make the best out of your netbeans ide. I'll introduce code templates.
Code templates are simply snippets of code which we use frequently and therefore we make them shorter to save us typing. There are many builtin templates in netbeans and we can add ours to them. To use code templates simply type the short form of the template and press the tab key. Some of the inbuilt code templates include: sout -- System.out.println("" ; //The cursor will be placed within the quotes psvm -- public static void main(String[] args){} St -- String fa -- false if -- if{} ife -- if{}else{} etc Now try the above for yourself. Type them then press the tab key. There are many more built-in code templates available to you in netbeans and not just for java but for most of the languages supported by netbeans. You can check them in the Options>Editor>Code Templates.
You can also create your own code templates depending on what you use frequently. We will create a code template for catching exceptions. There should be a builtin template for try catch but we will just create this to show how it is done. Open Options>Editor>Code Templates. Click New, type the short form for your new template, we will name ours error. The template is then created. Within the expanded text area, type the following:
try{ ${cursor} }catch(Exception exc){ }
The ${cursor} is where the user's cursor will be placed when the template is inserted.
Provided that you setup your shortcuts as we did in the first lesson then the following shortcuts will work for you. If you didn't set them up, then go to options, keymap and change netbeans to eclipse.
Ctrl-shift-O == This is to organize your imports. That is, if you use classes in your code which you need to import, pressing this shortcut helps you automatically import them. Try this, type Scanner and press Ctrl-shift-O. this will add import java.util.Scanner; to the top of your file.
Ctrl-shift-F == format code. This is used to format your code. This handles your indentation and generally makes your code look better.
That's all for now. I'll be back soon. Cheers Boss! Please keep the ball rolling... I have jst got a laptop and a generator... I want to perfect my java skills in two months... |
Jobs/Vacancies › Re: A Message For The Unemployed. by realowded(m): 3:40pm On Jan 10, 2015 |
Dcmg: You see,the society has brainwashed a lot of youths on what success is. To the society,success is going to the university,get a degree then get a well paying job,after that is to get married have kids then in your old age you retire,recieve pension and wait for your death.Is this life? The youths of today are living under pressure to succeed on the wrong purpose. Not even everybody who earn million bucks are fulfilled and satisfied with their lifes.Some millionaire are even living in depression and frustration cos they are not doing what they really like,or they aren't living the life they really ought to live. If i was to advice my 16-18 yrs old self,i would advice him not to rush into the university just yet. I would advice him to spend as much time,weeks,months or even years finding his trueself/bestself.I would tell him think of what he is really passionate about doing for the rest of his life,i would tell to think about what makes him come alive the most,i would tell him to search his heart well and think about what will bring him the greatest fulfillment in life,i would tell him that if today was the last day of his life,what would he rather be doing so that people would always remember him for that or what does he want people to remember him for. I would tell him to find his talent and do what he is passionate about and not try to please anybody,for doin things against your own heart desires just to please the society is very overrated and a fallacy,what you will get at best is depression and frustration. I would tell him its better to live a short and fulfilling life than a long and frustrating life because the society has conditioned you to think that's how a successful life should be like. Mehn,not everybody will get a job.Find your trueself and live a purposeful life,nature will welcome you with open arms when you'v discovered your trueself and living it.Everything will just be flowing. If you know your trueself and living it,you won't have time to be jealous about other peoples success There is nothing more motivating as this.... This is the best thing to tell any human!... Please, keep preaching this bro... |
Jobs/Vacancies › Re: A Message For The Unemployed. by realowded(m): 3:27pm On Jan 10, 2015 |
[q
uote author=Wittylens post=29667473]To the unemployed youths :
you can take blogging as a full time profession..
Blogging pays handsomely if you work hard
You can contact me if you need help getting started[/quote]How do I start? |
Phones › Re: BBM On Android And Related Issues by realowded(m): 3:50pm On Jan 01, 2015 |
WCUB3: Solution to bbm not connecting over mobile network on MTN kkkossy DarryOsh
Please do the following on your phone: Go to SETTINGS>MORE SETTINGS>MOBILE NETWORKS>ACCESS POINT NAMES Select MTN GPRS or MTN ACCESS (whichever you see), select PROXY and remove the values there and select OK. Go to PORT and do the same thing. So your PROXY and PORT will change to NOT SET. Next press the menu button on the left of your phone and select SAVE Restart your phone afterwards and launch your BBM, you should get a positive response. It worked bro.... Thanks a lot.... Even MTN customer couldn't solve it..... |
Agriculture › Re: What's Best To Do With 1 Million Naira In Agriculture? by realowded(m): 9:23pm On Dec 19, 2014 |
adaybayor: with 1m you can earn btw 250k to 350k monthly on agric, if you want to know how add my pin 7CE131F0 and I will share some ideas with you. cant put my business idea on a public forum. What difference does it make, if he decides to publicize it after u gave him. If it's not dubious, you won't hoard it. |
Jobs/Vacancies › Re: Stanbic IBTC Bank Is Recruiting by realowded(m): 4:06pm On Dec 14, 2014 |
How real is this information? Submitting hard copy of CV is outdated. |
Phones › Re: Finally Airtel Android Data Plans? by realowded(m): 8:12pm On Jul 17, 2014 |
I am currently using the opera mini planand whatsapp...make 400...I think am enjoying it |
Webmasters › Companion Cd For Php 6/mysql Programming For The Absolute Beginner: by realowded(op): 10:32am On Jan 23, 2012 |
please,where can i get to download the companion CD for PHP 6/MySQL Programming for the Absolute Beginner, ? i have the pdf version, i need the CD badly.Please get me sure link to get it, i have searched so , it seem so impossible but i beleive nothing in impossible with internet, please help me out. |