Chapter 2 Clarifications How to see the results of a statement What is a Logical Flow?
What is the result of a statement? How do you see what the result is? When you have the following code, how do you know what the result was? public class TestMath { public static void main(String[] args) { Math.pow(10, 4); }// end main }// end class
Why use System. out. println(); Why use System.out.println(); ? It lets you see the result to the screen Using System.out.println(); in the code, lets you see the result of the statement. public class TestMath { public static void main(String[] args) { System.out.println(Math.pow(10, 4)); }// end main }// end class
To store the result of the statement Assigning a variable the result of a statement lets you store that in memory to be used later. public class TestMath { public static void main(String[] args) { double result = Math.pow(10, 4); System.out.println(result); }// end main }// end class
When can I perform a calculation on variables? Can the following calculation be performed? public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); int y = x * x; int x = input.nextInt(); }// end main } //end class
Does the user know he or she needs to enter data? import java.io.*; import java.util.*; public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); int x = input.nextInt(); int y = x * x; }// end main } //end class
How informative is this to the user? public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); System.out.println("Please enter a number:"); int x = input.nextInt(); int y = x * x; System.out.println(y); }// end main } //end class
Useful information is now provided to the user public class Chapter2Clarification{ public static void main(String [] args){ Scanner input = new Scanner(System.in); System.out.println("Please enter a number:"); int x = input.nextInt(); System.out.println("Your number is " + x); int y = x * x; System.out.println(y + " is " + x + " squared."); }// end main } //end class