Mr. Data
From Huben's Wiki
(Created page with "This is just thrown together to record Chapter 1 activities. * Two's Compliment Worksheet * Computer-Oriented Dimensional Analysis Problems * Binary/Hexadecimal Worksheet * Dimen...") |
|||
Line 11: | Line 11: | ||
Write a class with a main() that has: | Write a class with a main() that has: | ||
* an int variable initialized to 2147483645 | * an int variable initialized to 2147483645 | ||
− | * a byte variable | + | * a byte variable initialized to 125 |
− | * a char variable | + | * a char variable initialized to 65530 |
* a loop counting from 1 to 10. In the loop: | * a loop counting from 1 to 10. In the loop: | ||
− | ** | + | ** print each variable as an (int) |
** increment each variable | ** increment each variable | ||
What happens to each variable and why? | What happens to each variable and why? | ||
+ | |||
+ | <pre> | ||
+ | class Counting | ||
+ | { | ||
+ | public static void main(String[] args) | ||
+ | { | ||
+ | byte myByte = 120; | ||
+ | char myChar = 65530; | ||
+ | int myInt = 2147483645; | ||
+ | System.out.println("Byte\tChar\tInt"); | ||
+ | for(int i = 0; i < 10; i++) | ||
+ | { | ||
+ | myByte++; | ||
+ | myChar++; | ||
+ | myInt++; | ||
+ | System.out.println(((int) myByte) + "\t" + ((int) myChar) + "\t" + myInt); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </pre> |