JAVA - 'Fun with Numbers' for absolute beginners
the purpose of this tutorial is to get beginner java programmers familiar with variable types int and doubble, as well as with mathematical calculations. it is a simple program that beginners can make, but it covers a lot of basics to understanding numbers and their variable types.
AI
สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ซอร์สโค้ด
<blockquote>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><br>
</font></p>
<hr>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><u>INTRO TO JAVA (PART 2) -
WRITTEN BY: M.WORTHINGTON [12.08.01]</u><br>http://mixednuts.8bit-religion.com<br>
<br>
...well if you've checked out the <a href="http://mixednuts.8bit-religion.com/java.php?id=main">first tutorial</a> and everything went as planned, you made
your first program and played with it, than you are definetly bored with it and ready to
learn more. in this second installment to the java tutorials, you'll be learning about
number variables and some mathematical operations.<br>
<br>
in our class FunWithNumbers we will be using two different variable types: int and double.
an int can be any integer (-1,0,1,2...) from -2147483648 (MIN_VALUE) to 2147483648
(MAX_VALUE). and int does not support decimals; that is where the variable type double
comes in. examples of what a double variable could be .5, 3.14, 2., 19.8888, and so on.<br>
<br>
in this program, we will also be using some simple math calculations. they are as follows:
+ for addition (while the plus sign is used for math,
it is also used in printing out multiple things in a line or adding on to a string. so
when you think of +, think 'plus' or 'and'.<br>
- for subtraction<br>
* for multiplication<br>
/ for division<br>
% to get the remainder of one number dividing into another<br>
<br>
<u>OBJECTIVE</u> <br>
to create, use, and manipulate numbers with variable types such as int and double. <br>
<br>
<u>PROGRAM</u><br>
<br>
public class FunWithNumbers<br>
{<br>
public static void main(String[] args)<br>
{<br>
int a = 2;<br>
int b = 5;<br>
double d;<br>
int e;<br>
System.out.println("a + b = " + (a+b)); // Line 1<br>
System.out.println("a - b = " + (a-b)); // Line 2<br>
System.out.println("a * b = " + (a*b)); // Line 3<br>
d = (b/a);<br>
System.out.println("d = " + d); // Line 4<br>
d = (5./2.);<br>
System.out.println("d = " + d); // Line 5<br>
e = (b/a);<br>
System.out.println("e = " + e); //Line 6<br>
System.out.println("b / a = " + (b/a) + " b % a =
" + (b%a)); // Line 7<br>
System.out.println("a / b = " + (a/b) + " a % b =
" + (a%b)); // Line 8<br>
} //main<br>
} //class</font></p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><u>ABOUT THE PROGRAM</u><br>
on each line of coding that is going to print something out is a comment that has an
assigned number line. this is just so referring to each line will be easier to understand.<br>
<br>
<u>OUTPUT</u><br>
be sure to compile the program and then run it. refer back to the <a
href="http://mixednuts.8bit-religion.com/java.php?id=tutorial1">first tutorial</a> for
instructions.</font></p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">the following is output
from each line(minus the line reference) as you should have when you run the program:<br>
<br>
Line 1: a + b = 7<br>
Line 2: a - b = -3<br>
Line 3: a * b = 10<br>
Line 4: d = 2.0<br>
Line 5: d = 2.5<br>
Line 6: e = 2<br>
Line 7: b / a = 2 b % a = 1<br>
Line 8: a / b = 0 a % b = 2<br>
<br>
<u>EXPLANATION</u><br>
this is just basic mathematics. the only real parts to explain would be the different
outputs of the variable d. on line 4 it prints out 2.0 rather than 2.5, which is on line
5. the reason for this is because in the first case, d equals the division of two
integers. while, on line 5, d equals 5. divided by 2. which both have decimal points and
therefore will produce what comes up after the decimal place.</font></p>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">if you're still having
trouble with the program and understanding it, your best bet is to just mess around with
it. change up the variables, variable types, values, and calculations; before running the
program, try to predict what is going to be printed out. <br>
<br>
any other questions, hit up the <a href="http://mixednuts.8bit-religion.com/forum.php">message
boards</a>. if you chat there you can easily go ahead of tutorials and learn more
programming.<br>
<br>
please let me know what you think of this tutorial by going to the <a
href="http://mixednuts.8bit-religion.com/forum.php">message boards</a> or the <a
href="http://mixednuts.8bit-religion.com/contactpage.php">contact page</a> to submit your
comments. thank you.<br>
</font></p>
<hr>
<p> </p>
</blockquote>
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine