new semester, new repo structure
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package programmingexam1_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class LeapYear {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter a year: ");
|
||||
int year = input.nextInt();
|
||||
|
||||
// Check if the year is a leap year
|
||||
boolean isLeapYear
|
||||
= ((year % 4 == 0) && (year % 100 != 0 )|| (year % 400 == 0));
|
||||
|
||||
// Display the result
|
||||
System.out.println(year + " is a leap year? " + isLeapYear);
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package programmingexam1_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class ProgrammingExam1_CalebFontenot {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// TODO code application logic here
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package programmingexam1_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class QuotientAndRemainder {
|
||||
public static void main(String[] args) {
|
||||
// Define variables
|
||||
int number1, number2, quotient, remainder;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for variables
|
||||
System.out.print("Enter 2 variables and I will calculate the "
|
||||
+ "quotient and the remainder: ");
|
||||
number1 = input.nextInt();
|
||||
number2 = input.nextInt();
|
||||
|
||||
// Compute!
|
||||
quotient = number1 / number2;
|
||||
remainder = number1 % number2;
|
||||
|
||||
// Print output:
|
||||
System.out.println("The quotient is: " + quotient);
|
||||
System.out.println("The remainder is: " + remainder);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package programmingexam1_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class QuotientAndRemainderOfNumbersInAnyOrder {
|
||||
public static void main(String[] args) {
|
||||
// Define variables
|
||||
int number1, number2, quotient, remainder;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for variables
|
||||
System.out.print("Enter 2 variables and I will calculate the "
|
||||
+ "quotient and the remainder: ");
|
||||
number1 = input.nextInt();
|
||||
number2 = input.nextInt();
|
||||
|
||||
// Compute!
|
||||
if (number1 <= number2) {
|
||||
System.out.println(number1 + " < " + number2 + "!");
|
||||
int tmp = number2; // temp variable to store the number
|
||||
number2 = number1;
|
||||
number1 = tmp;
|
||||
}
|
||||
|
||||
quotient = number1 / number2;
|
||||
remainder = number1 % number2;
|
||||
|
||||
// Print output:
|
||||
System.out.println(number1 + " / " + number2 + " =");
|
||||
System.out.println("The quotient is: " + quotient);
|
||||
System.out.println("The remainder is: " + remainder);
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package programmingexam1_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class TwoLargerOfThe3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int _1, _2, _3; // Note to Markou: I find numbers easier to compare in my head than variables, hence my use of them here.
|
||||
int firstLargest = 0, secondLargest = 0;
|
||||
|
||||
// Setup scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
while (true) {
|
||||
// Prompt for input
|
||||
System.out.print("Enter 3 numbers: ");
|
||||
_1 = input.nextInt();
|
||||
_2 = input.nextInt();
|
||||
_3 = input.nextInt();
|
||||
|
||||
// Compute!
|
||||
if (_1 <= _3 & _2 <= _3) { // Is _3 the largest?
|
||||
firstLargest = _3; // Yes!
|
||||
if (_2 >= _1) { // Is _2 larger than _1?
|
||||
secondLargest = _2; //Then _2 must be the second largest.
|
||||
} else {
|
||||
secondLargest = _1; //Then _1 must be the second largest.
|
||||
}
|
||||
}
|
||||
if (_3 <= _2 & _1 <= _2) { // Is _2 the largest?
|
||||
firstLargest = _2; // Yes!
|
||||
if (_3 >= _1) { //Is _3 larger than _1?
|
||||
secondLargest = _3; // Then _3 must be the largest.
|
||||
} else {
|
||||
secondLargest = _1; // Then _1 must be the largest.
|
||||
}
|
||||
}
|
||||
if (_3 <= _1 & _2 <= _1) { // Is _1 the largest?
|
||||
firstLargest = _1; // Yes!
|
||||
if (_3 >= _2) {// Is _3 larger than _2?
|
||||
secondLargest = _3; // Then _3 must be the largest.
|
||||
} else {
|
||||
secondLargest = _2; // Then _2 must be the largest.
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (_1 == _2 | _1 == _3 | _2 == _3) {
|
||||
System.out.println("Some numbers equal. Running additional checks...");
|
||||
if (_1 == _2) {
|
||||
if (_1 > _3) { // Is _3 smaller than _1 and _2?
|
||||
firstLargest = _1;
|
||||
secondLargest = _3;
|
||||
}
|
||||
}
|
||||
if (_1 == _3) {
|
||||
if (_3 > _2) { // Is _2 smaller than _1 and _3?
|
||||
firstLargest = _3;
|
||||
secondLargest = _2;
|
||||
}
|
||||
}
|
||||
if (_2 == _3) {
|
||||
if (_3 > _1) { // Is _1 smaller than _2 or _3?
|
||||
firstLargest = _3;
|
||||
secondLargest = _1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
// Output
|
||||
System.out.println("The first largest is " + firstLargest + " and the second largest is " + secondLargest);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user