Presentation is loading. Please wait.

Presentation is loading. Please wait.

Something about Java Introduction to Problem Solving and Programming 1.

Similar presentations


Presentation on theme: "Something about Java Introduction to Problem Solving and Programming 1."— Presentation transcript:

1 Something about Java Introduction to Problem Solving and Programming 1

2 Parts of a program Structure Code Action Code Comments – Directions to the human on how to read the program 2

3 Object-Oriented Programming Programmers – Write classes – Use objects Java is Object-Oriented – We will write at least one class for every problem 3

4 } // end main() public static void main(String[] args) { public class FirstProgram { }// end FirstProgram 4 Every program in Java is a class We name the class (same name as the file) One class has a method named “main” it is the start

5 import java.util.Scanner; System.out.println("Please enter two numbers and"); System.out.println("I will compute their sum."); int n1; int n2; int sum; Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); System.out.println("Their sum is"); System.out.println(sum); }// end main() public static void main(String[] args) { public class FirstProgram { }// end FirstProgram Scanner class is in another package (and we want to use it) Inform the user Declare variables Prepare to read from the keyboard Show the user the answer 5 Get the input sum = n1 + n2; Do the math

6 import java.util.Scanner; System.out.println("Please enter two numbers and"); System.out.println("I will compute their sum."); int n1; int n2; int sum; Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); System.out.println("Their sum is"); System.out.println(sum); }// end main() public static void main(String[] args) { public class FirstProgram { }// end FirstProgram 6 sum = n1 + n2; Comments begin // (these are not typical comments)


Download ppt "Something about Java Introduction to Problem Solving and Programming 1."

Similar presentations


Ads by Google