lab & assignment

This commit is contained in:
k0rrluna 2024-10-23 15:11:20 +03:00
parent 8928b8471a
commit b1f377bfec
9 changed files with 126 additions and 3 deletions

View File

@ -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");
}

24
labs/lab2/Average.java Normal file
View File

@ -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);
}
}

20
labs/lab2/Errors.java Normal file
View File

@ -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);
}
}

23
labs/lab2/Names.java Normal file
View File

@ -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 ();
}
}

16
labs/lab2/Table.java Normal file
View File

@ -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");
}
}

Binary file not shown.

18
labs/lab2/maths.java Normal file
View File

@ -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));
}
}

22
labs/lab2/plusTest.java Normal file
View File

@ -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.");
}
}