Main » Articles » Computer Science » 2014

More Funny Symbols and Loops
[SL & HL] .. Lots more Loops

More Loops
 
// Trace each loop (that means predict what it will print)
// After making your prediction ON PAPER, you may wish
// to run it in NetBeans and check your prediction.
 
for(int x = 0; x < 10; x = x+2)
{
 System.out.println(x);
}
 
for(int y = 1; y < 10; y = y+2)
{
 System.out.println(y);
}
 
for(double c = 0.1; c < 10; c = c+0.1)
{
 System.out.println(c);
}
 
int total = 0;
for(int n = 5; n <= 20; n = n+5)
{
 total = total + n;
 System.out.println(total);
}
 
double sum = 0;
for(double d = 10; d != 0; d = d-1)
{
 sum = sum + n;
 System.out.println(total);
}
 
int k = 1000;
for(int p = 1; p <= 5; p++)
{
 System.out.println(k);
 k = k / 2;
}
 
for(int m = 100; m != 0; m = m - 7)
{
 System.out.println(m);
}
 
// Now practice writing your own loops to do the following:
//
// - count 3, 6, 9, ... 99
// - count 1, 2, 4, 8, 16, ... 1024
// - add up 1+2+4+8+...+512
// - add up 11+12+13+14...+19
// - print all the perfect squares up to 1000 : 1 , 4 , 9 , 16 , 25 ,... 900 , 961
// - add up 1/2 + 1/3 + 1/4 + 1/5 + ... until the total is greater than 5
// Does that actually happen, or is this an infinite loop?
//
// Write your solutions in NetBeans and test them.
 

[HL] :

Logic operations : 12 & 6 = 4 , 12 | 6 = 14 , 12 ^ 6 = 10 , 12 % 6 = 0 ???
 
Special characters : \u221a , \u00b2 , \n , \t , \q , \\
You can see lots of mathematical Unicode symbols in tables like this:
http://www.ssec.wisc.edu/~tomw/java/unicode.html#x2200

Try reading this : http://unicode.org/standard/WhatIsUnicode.htm
Category: 2014 | Added by: Jerry (10/10/2011)
Views: 283 | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]
Section categories
2014 [20]
2013 [57]
Statistics
Map
Login form