Class Notes (835,730)
Canada (509,354)
COMP 1405 (38)
Lecture

comp1005/1405_c6_28092010.pdf

6 Pages
85 Views
Unlock Document

Department
Computer Science
Course
COMP 1405
Professor
Christine Laurendeau
Semester
Fall

Description
Lecture 6 Program 1 ///The following program shows the usage of the if and else statement import java.util.Scanner; //scanner library used for the grade input class Ch3_0IfElse { public static void main (String args[]) { System.out.print("Enter your grade (1-100): "); //outputs "Enter your grade (1-100): " int input = new Scanner(System.in).nextInt(); System.out.println("You have entered: " + input); //outputs "You have entered: " + input if (input < 50) System.out.println("Oh well there's always a next term"); else System.out.println("Congratulations"); /*If the argument in the if(argument) is valid * System.out.println("Oh well there's always a next term"); * will run, else it prints System.out.println("Congratulations"); * * signs * == equals, <= less or equal to, >= greater or equal to * < less than, > greater than * */ } } Lecture 6 Program 2 ///The following program shows the usage of the if and else statement import java.util.Scanner; //scanner library used for the grade input class Ch3_0IfElse2 { public static void main (String args[]) { System.out.print("Enter your grade (1-100): "); //outputs "Enter your grade (1-100): " int input = new Scanner(System.in).nextInt(); System.out.println("You have entered: " + input); //outputs "You have entered: " + input if (input < 50) { System.out.println("Oh well there's always a next term"); } else if (input > 100) { System.out.println("You can't have over 100%"); } else { System.out.println("Congratulations"); System.out.println("Your score is: " + input); } /*If the argument in the if(argument) is valid * System.out.println("Oh well there's always a next term"); * will run, else it will move onto the next if argument * System.out.println("You can't have over 100%"); * if non of the if arguments are true it will be left over with the * else statement * System.out.println("Congratulations"); * System.out.println("Your score is: " + input); * Notice how when the statements gets complicated, you can use the {} * brackets to group them * */ } } Lecture 6 Class 1 //The following class is required for the Ch3_1IdenticalClass program class Ch3_1IdenticalClassObject { } Lecture 6 Program 3 //The following program shows the .equals() function class Ch3_1IdenticalClass { public static void main (String args) { Ch3_1IdenticalClassObject myCar, yourCar, bobsCar; //Defines 3 objects myCar = new Ch3_1IdenticalClassObject();
More Less

Related notes for COMP 1405

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit