diff --git a/ch02/Assigningvalues.java b/ch02/Assigningvalues.java new file mode 100644 index 0000000..fd76413 --- /dev/null +++ b/ch02/Assigningvalues.java @@ -0,0 +1,19 @@ +package PACKAGE_NAME; + +public class Assigningvalues +{ + public static void main(String[] args) + { + String txt = "Fantastic"; + String lang = "Java"; + txt += lang; // Assign concatenated String + System.out.println("Add & Assign Strings;" + txt); + int sum = 10; + int num = 20; + sum += num ; // Assign result ( 10 + 20 = 30 ) + System.out.println( "Add & Assign Integers: " + sum ) ; + int factor = 5 ; + sum *= factor ; // Assign result ( 30 x 5 = 150 ) + System.out.println( "Multiplication sum: " + sum ) ; + } +} diff --git a/ch02/Constants.java b/ch02/Constants.java new file mode 100644 index 0000000..7153d65 --- /dev/null +++ b/ch02/Constants.java @@ -0,0 +1,19 @@ +public class Constants + +{ + public static void main ( String[] args ) + { + final int TOUCHDOWN = 6; + final int CONVERSION = 1; + final int FIELDGOAL = 1; + + + int td, pat, fg, total; + td = 4 * TOUCHDOWN; + pat = 3 * CONVERSION; + fg = 2 * FIELDGOAL; + total = (td + pat + fg); + System.out.println("Score: " + total ); + + } +} diff --git a/ch02/DataTypes.java b/ch02/DataTypes.java new file mode 100644 index 0000000..b1470eb --- /dev/null +++ b/ch02/DataTypes.java @@ -0,0 +1,20 @@ +public class DataTypes +{ + public static void main(String[] args) + { + + char letter = 'M'; + String title = "Java in easy steps "; + int number = 365; + float decimal = 98.6f; + boolean result = true; + System.out.println("Initial is " + letter ); + System.out.println("Book is " +title ); + System.out.println("Days are " + number ); + System.out.println("Temperature is " + decimal ); + System.out.println("Answer is " + result ); + + + + } +} diff --git a/ch02/Date.java b/ch02/Date.java new file mode 100644 index 0000000..f99c54a --- /dev/null +++ b/ch02/Date.java @@ -0,0 +1,9 @@ +public class Date +{ + public static void main(String[] args) + { // gnerate some simple output + System.out.println("hello "); + int num = 13 + + } +} \ No newline at end of file diff --git a/ch02/Doingarithmetic.java b/ch02/Doingarithmetic.java new file mode 100644 index 0000000..236d49f --- /dev/null +++ b/ch02/Doingarithmetic.java @@ -0,0 +1,19 @@ +public class Doingarithmetic +{ + public static void main(String[] args) + { + int num = 100; + int factor = 20; + int sum = 0; + sum = num + factor; // 100 + 20 + System.out.println("Addition sum: " + sum); + sum = num - factor; // 100 - 20 + System.out.println("Subtrsction sum: " + sum); + sum = num * factor ; // 100 x 20 + System.out.println( "Multiplication sum: " + sum ) ; + sum = num / factor ; // 100 / 20 + System.out.println( "Division sum:" + sum ) ; + + + } +} diff --git a/ch02/FirstVariable.java b/ch02/FirstVariable.java new file mode 100644 index 0000000..1bc2f05 --- /dev/null +++ b/ch02/FirstVariable.java @@ -0,0 +1,14 @@ +public class FirstVariable +{ + public static void main(String []args ) + { + String message = "Initial value"; + System.out.println (message); + + message = "Modified value"; + System.out.println (message); + + } + + +} diff --git a/ch02/Variables.java b/ch02/Variables.java index a295abf..d238665 100644 --- a/ch02/Variables.java +++ b/ch02/Variables.java @@ -1,10 +1,12 @@ /** * Examples from Chapter 2. */ -public class Variables { - - public static void main(String[] args) { +public class Variables +{ + public static void main(String[] args) + { + //Stephanie String message; int x; @@ -59,7 +61,7 @@ public static void main(String[] args) { System.out.println(0.1 * 10); System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 - + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); + + 0.1 + 0.1 + 0.1 + 0.1 + 0.1); double balance = 123.45; // potential rounding error int balance2 = 12345; // total number of cents diff --git a/ch05/Comparison.java b/ch05/Comparison.java new file mode 100644 index 0000000..b086c90 --- /dev/null +++ b/ch05/Comparison.java @@ -0,0 +1,22 @@ +import java.sql.SQLOutput; + +public class Comparison +{ + + public static void main(String[] args) + { + String txt = "Fantastic "; + String lang = "Java " ; + boolean state = ( txt == lang ) ; // Assign test result + System.out.println( "String Equality Test: " + state ) ; + state = ( txt != lang ) ; //Assign test result + System.out.println( "String Inequality Test:" + state ) ; + int dozen = 12 ; + int score = 20 ; + state = ( dozen > score ) ; //Assign result + System.out.println( "Less Than Test" + state ) ; + + + } +} + diff --git a/ch05/Condition.java b/ch05/Condition.java new file mode 100644 index 0000000..732e220 --- /dev/null +++ b/ch05/Condition.java @@ -0,0 +1,17 @@ +public class Condition +{ + + public static void main(String[] args) + + { + int num1 = 1357; + int num2 = 2468; + String result ; + result = ( num1 % 2 != 0 ) ? "Odd": "Even"; + System.out.println(num2 + " is " + result); + result = ( num2 % 2 != 0 ) ? "Odd" : "Even" ; + System.out.println( num2 + " is " + result ) ; + } + + +} diff --git a/ch05/Else.java b/ch05/Else.java new file mode 100644 index 0000000..ee2f8a6 --- /dev/null +++ b/ch05/Else.java @@ -0,0 +1,15 @@ +public class Else +{ + public static void main(String[] args) + { + int hrs = 21; + if (hrs < 21) ; + + else if (hrs < 18) ; + + { + System.out.println(" Good morning; " + hrs); + } + + } +} diff --git a/ch05/If.java b/ch05/If.java new file mode 100644 index 0000000..904cc22 --- /dev/null +++ b/ch05/If.java @@ -0,0 +1,23 @@ +public class If +{ + + public static void main(String[] args) + + { + if (5 > 1) System.out.println("Five is greater than one."); + if (2 < 4) + + { + System.out.println("Test succeeded."); + System.out.println("Number is 6-9 inclusive, or 12" ); + + } + + int num = 8 ; + + { + if (((num > 5) && (num < 10)) || (num == 12)) + System.out.println("Number is 6-9 inclusive, or 12"); + } + } +} \ No newline at end of file diff --git a/ch05/Logic.java b/ch05/Logic.java new file mode 100644 index 0000000..64bf1a7 --- /dev/null +++ b/ch05/Logic.java @@ -0,0 +1,16 @@ +public class Logic +{ + public static void main( String[] args ) + { + boolean yes = true ; + boolean no = false ; + System.out.println( "Both YesYes True: " + ( yes && yes ) ) ; + System.out.println( "Both YesNo True: " + ( yes && no ) ) ; + System.out.println( "Either YesYes True: " + ( yes && yes )) ; + System.out.println( "Either YesNo True: " + ( yes || no ) ) ; + System.out.println( "Either NoNo True: " + ( no || no ) ) ; + System.out.println( "Original Yes Value: " + yes ) ; + System.out.println( "Inverse Yes Value: " + !yes ) ; + + } +} diff --git a/ch05/LogicMethods.java b/ch05/LogicMethods.java new file mode 100644 index 0000000..a5f028b --- /dev/null +++ b/ch05/LogicMethods.java @@ -0,0 +1,26 @@ +public class LogicMethods +{ + public static void main(String[] args ) + { + System.out.println("Logic Methods"); + printIsLargeOrSmall(100) ; + printIsLargeOrSmall(75); + } + + private static void printIsLargeOrSmall (int number) + { + if( number > 99 ) + if( number < 10 ) + + + { + System.out.println("The number is large " ) ; + System.out.println("The number is small ") ; + } + + } + + + + +} \ No newline at end of file diff --git a/ch05/Precedence.java b/ch05/Precedence.java new file mode 100644 index 0000000..0780449 --- /dev/null +++ b/ch05/Precedence.java @@ -0,0 +1,18 @@ +public class Precedence + +{ + public static void main(String[] args ) + { + int sum = 32 - 8 + 16 * 2 ; // 16 x 2 = 32, + 24 + 56 + System.out.println( "Default order: " + sum ) ; + sum = ( 32 - 8 + 16 ) * 2 ; // 24 + 16 = 40, x 2 + 80 + System.out.println( "Specified order: " + sum ) ; + sum = ( 32 - (8 + 16) ) * 2 ; // 32 - 24 + 8, * 2 = 80 + System.out.println( "Nested specific order: " + sum ) ; + + + + } + + +}