Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Clarifications

Similar presentations


Presentation on theme: "Chapter 2 Clarifications"— Presentation transcript:

1 Chapter 2 Clarifications
How to see the results of a statement What is a Logical Flow?

2 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

3 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

4 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

5 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

6 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

7 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

8 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


Download ppt "Chapter 2 Clarifications"

Similar presentations


Ads by Google