diff --git a/assignments/assignment1/leapYear.java b/assignments/assignment1/leapYear.java index 5568ba5..aa1a2b0 100644 --- a/assignments/assignment1/leapYear.java +++ b/assignments/assignment1/leapYear.java @@ -6,10 +6,10 @@ public class leapYear { System.out.println("Enter year!"); int year = scan.nextInt(); - if (year%4 == 0 || year%100 == 0 && year%400 == 0 && year > 1581) { + if (year < 1582){ + System.out.println("ENTER MORE THAN YEAR 1581!"); + } else if (year%4 == 0 || year%100 == 0 && year%400 == 0) { System.out.println("The year "+year+" is a leap year!"); - } else if (year < 1582){ - System.out.println("ENTER MORE THAN YEAR 1581!"); } else { System.out.println("The year: "+year+" isn't leap year"); } diff --git a/labs/lab2/Average.java b/labs/lab2/Average.java new file mode 100644 index 0000000..b8f14a8 --- /dev/null +++ b/labs/lab2/Average.java @@ -0,0 +1,24 @@ +// ******************************************************************* +// Average.java +// +// Read three integers from the user and print their average +// ******************************************************************* +import java.util.Scanner; +public class Average +{ + public static void main(String[] args) + { + int val1, val2, val3; + double average; + Scanner scan = new Scanner(System.in) ; + // get three values from user + System.out.println("Please enter three integers and " + + "I will compute their average"); + val1 = scan.nextInt(); + val2 = scan.nextInt(); + val3 = scan.nextInt(); + + average = (val1 + val2 + val3)/3; + System.out.println(average); + } +} \ No newline at end of file diff --git a/labs/lab2/Errors.java b/labs/lab2/Errors.java new file mode 100644 index 0000000..f9c7d6a --- /dev/null +++ b/labs/lab2/Errors.java @@ -0,0 +1,20 @@ +// File: Errors.java +// Purpose: A program with lots of syntax errors +// Correct all of the errors (STUDY the program carefully!!) +import java.util.Scanner; +public class Errors +{ + public static void main (String[] args) + { + String Name; // Name of the user + int number; + int numSq; + Scanner scan = new Scanner(System.in); + System.out.println ("Enter your name, please: "); + Name = scan.nextLine(); + System.out.println ("What is your favorite number?"); + number = scan.nextInt(); + numSq = number * number; + System.out.println (Name+", the square of your number is " + numSq); +} +} \ No newline at end of file diff --git a/labs/lab2/Names.java b/labs/lab2/Names.java new file mode 100644 index 0000000..ec39de6 --- /dev/null +++ b/labs/lab2/Names.java @@ -0,0 +1,23 @@ +// *************************************************************** +// Names.java +// +// Prints a list of student names with their hometowns +// and intended major +// *************************************************************** +public class Names +{ + // ------------------------ + // main prints the list + // ------------------------ + public static void main (String[] args) + { + System.out.println (); + System.out.println ("\tName\t\tHometown\t\tMajor"); + System.out.println ("\t====\t\t========\t\t====="); + System.out.println ("\tSally\t\tRoanoke\t\t\tComputer Major"); + System.out.println ("\tAlexander\tWashington\t\tMath Major"); + System.out.println ("\tKoray\t\tAltinsoy\t\tComputer Major"); + System.out.println ("\tBurak\t\tKarakilic\t\tComputer Major"); + System.out.println (); + } +} \ No newline at end of file diff --git a/labs/lab2/Table.java b/labs/lab2/Table.java new file mode 100644 index 0000000..c59615a --- /dev/null +++ b/labs/lab2/Table.java @@ -0,0 +1,16 @@ +public class Table { + public static void main(String[] args) { + System.out.println("///////////////////\\\\\\\\\\\\\\\\\\\\\\\\"); + System.out.println("==\tStudent Points\t=="); + System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\///////////////////"); + System.out.println(); + System.out.println("Name\t\tLab\tBonus\tTotal"); + System.out.println("----\t\t---\t-----\t-----"); + + System.out.println("Joe\t\t43\t7\t50"); + System.out.println("William\t\t50\t8\t58"); + System.out.println("Mary Sue\t39\t10\t49"); + System.out.println("Koray\t\t90\t10\t100"); + System.out.println("Burak\t\t10\t10\t20"); + } +} diff --git a/labs/lab2/chapter2_lab-2.pdf b/labs/lab2/chapter2_lab-2.pdf new file mode 100644 index 0000000..c17029b Binary files /dev/null and b/labs/lab2/chapter2_lab-2.pdf differ diff --git a/labs/lab2/chapter2_lab-2.pdfZone.Identifier b/labs/lab2/chapter2_lab-2.pdfZone.Identifier new file mode 100644 index 0000000..e69de29 diff --git a/labs/lab2/maths.java b/labs/lab2/maths.java new file mode 100644 index 0000000..494269c --- /dev/null +++ b/labs/lab2/maths.java @@ -0,0 +1,18 @@ +public class maths { + public static void main(String args[]) { + int a = 3, b = 10, c = 7; + double w = 12.9, y = 3.2; + + System.out.println("a + b * c ="+(a+b*c)); + System.out.println("a - b - c ="+(a-b-c)); + System.out.println("a / b ="+(a/b)); + System.out.println("b / a ="+(b/a)); + System.out.println("a - b / c="+(a-b/c)); + System.out.println("w / y="+(w/y)); + System.out.println("y / w="+(y/w)); + System.out.println("a + w / b="+(a+w/b)); + System.out.println("a % b / y="+(a%b/y)); + System.out.println("b % a="+(b%a)); + System.out.println("w % y="+(w%y)); + } +} \ No newline at end of file diff --git a/labs/lab2/plusTest.java b/labs/lab2/plusTest.java new file mode 100644 index 0000000..2dcb0e7 --- /dev/null +++ b/labs/lab2/plusTest.java @@ -0,0 +1,22 @@ +// ******************************************************************* +// PlusTest.java +// +// Demonstrate the different behaviors of the + operator +// ******************************************************************* +public class PlusTest +{ + // ------------------------------------------------- + // main prints some expressions using the + operator + // ------------------------------------------------- + public static void main (String[] args) + { + System.out.println ("This is a long string that is the " + + "concatenation of two shorter strings."); + System.out.println ("The first computer was invented about " + 55 + + " years ago."); + System.out.println ("8 plus 5 is " + 8 + 5); + System.out.println ("8 plus 5 is " + (8 + 5)); + System.out.println (8 + 5 + " equals 8 plus 5."); + System.out.println ("Ten robins plus 13 canaries is "+(10+13)+" birds."); + } +} \ No newline at end of file