Scales are built on interval formulas. Diatonic scales (no added sharps or flats other than what is in the key signature) use only half steps and whole steps. With a diatonic scale you can follow the same interval pattern for major scales and one for minor scales. These patterns (as seen in the links) are
Whole Whole Half Whole Whole Whole Half which is often notated as
for major and
Whole Half Whole Whole Half Whole Whole notated as
WHWWHWW for minor.
*Note - An interval is the distance between two notes. (ex: C to C# is a half step)
Using these interval patterns you can start at your root note (the first note of the scale) and follow the pattern. For example with a C major scale you start with the root (which is C) and use the major interval pattern to find the rest of the scale. Which would be this:
root(C), whole step(D), whole step(E), half step(F), whole step(G), whole step(A), whole step(B), half step(C)
I would suggest trying a couple major and minor keys using the correct pattern to get the hang of it. If you get stuck look at a key signature chart or a circle of fifths to make sure you have the right notes in the key.
Here is a list of all the scale interval patterns if you are working with more than just diatonic scales:
Major Scale: R, W, W, H, W, W, W, H
Natural Minor Scale: R, W, H, W, W, H, W, W
Harmonic Minor Scale: R, W, H, W, W, H, 1 1/2, H (notice the step and a half)
Melodic Minor Scale: going up is: R, W, H, W, W, W, W, H
going down is: R, W, W, H, W, W, H, W
Dorian Mode is: R, W, H, W, W, W, H, W
Mixolydian Mode is: R, W, W, H, W, W, H, W
Ahava Raba Mode is: R, H, 1 1/2, H, W, H, W, W
A minor pentatonic blues scale (no sharped 5) is: R, 1 1/2, W, W, 1 1/2, W
R - root
W - whole step
H - half step
1 1/2 - a step and a half
I hope that helps. Good luck!