Download presentation
Presentation is loading. Please wait.
Published byBob Ewell Modified over 6 years ago
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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.