Reset author name to chosen name ✨
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.exam1_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class DayOfTheWeek {
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("\n\n Enter year (e.g. 2008): ");
|
||||
int year = input.nextInt();
|
||||
System.out.print("Enter month 1-12: ");
|
||||
int month = input.nextInt();
|
||||
if (month == 1) {
|
||||
month = 13;
|
||||
year = year - 1;
|
||||
}
|
||||
else if (month == 2) {
|
||||
month = 14;
|
||||
year = year - 1;
|
||||
}
|
||||
System.out.println("Enter the day of the month: 1-31: ");
|
||||
int dayOfMonth = input.nextInt();
|
||||
|
||||
int j = year / 100;
|
||||
int k = year % 100;
|
||||
|
||||
int dayOfWeek = (dayOfMonth
|
||||
+ 26 * (month + 1) / 10 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||
if (dayOfWeek == 0) {
|
||||
System.out.println("Day of the week is Saturday");
|
||||
}
|
||||
else if (dayOfWeek == 1) {
|
||||
System.out.println("Day of the week is Sunday");
|
||||
}
|
||||
else if (dayOfWeek == 2) {
|
||||
System.out.println("Day of the week is Monday");
|
||||
}
|
||||
else if (dayOfWeek == 3) {
|
||||
System.out.println("Day of the week is Tuesday");
|
||||
}
|
||||
else if (dayOfWeek == 4) {
|
||||
System.out.println("Day of the week is Wednesday");
|
||||
}
|
||||
else if (dayOfWeek == 5) {
|
||||
System.out.println("Day of the week is Thursday");
|
||||
}
|
||||
else if (dayOfWeek == 6) {
|
||||
System.out.println("Day of the week is Friday");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
|
||||
*/
|
||||
|
||||
package com.chloefontenot.exam1_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class Exam1_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.exam1_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class RandomMonth {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int number = (int) (Math.random() * 12 + 1);
|
||||
System.out.println("Random generated number is: " + number);
|
||||
switch (number) {
|
||||
case 1:
|
||||
System.out.println("Month is January"); break;
|
||||
case 2:
|
||||
System.out.println("Month is February"); break;
|
||||
case 3:
|
||||
System.out.println("Month is March"); break;
|
||||
case 4:
|
||||
System.out.println("Month is April"); break;
|
||||
case 5:
|
||||
System.out.println("Month is May"); break;
|
||||
case 6:
|
||||
System.out.println("Month is June"); break;
|
||||
case 7:
|
||||
System.out.println("Month is July"); break;
|
||||
case 8:
|
||||
System.out.println("Month is August"); break;
|
||||
case 9:
|
||||
System.out.println("Month is September"); break;
|
||||
case 10:
|
||||
System.out.println("Month is October"); break;
|
||||
case 11:
|
||||
System.out.println("Month is November"); break;
|
||||
case 12:
|
||||
System.out.println("Month is December"); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.exam1_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ar114
|
||||
*/
|
||||
public class TrianglePerimeter {
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Define variables
|
||||
int triEdge1, triEdge2, triEdge3;
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter 3 edges for a triangle: ");
|
||||
triEdge1 = input.nextInt();
|
||||
triEdge2 = input.nextInt();
|
||||
triEdge3 = input.nextInt();
|
||||
|
||||
// Compute and print output
|
||||
System.out.println(((triEdge1 + triEdge2) > triEdge3) ||
|
||||
((triEdge1 + triEdge3) > triEdge2) ||
|
||||
((triEdge2 + triEdge3) > triEdge1) ?
|
||||
"Input is valid" : "Invalid Input");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.exam2_mvn_practice_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Consecutive4Equals {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
while (true) {
|
||||
System.out.print("Enter the number of values, -1 to quit: ");
|
||||
int size = input.nextInt();
|
||||
if (size == -1) {
|
||||
System.out.println("goodbye!");
|
||||
break;
|
||||
}
|
||||
int[] values = new int[size];
|
||||
System.out.print("Enter the values: ");
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = input.nextInt();
|
||||
}
|
||||
if (isConsecutiveFour(values)) {
|
||||
System.out.println("The list has consecutive fours.");
|
||||
} else {
|
||||
System.out.println("The list has no consecutive fours.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isConsecutiveFour(int[] values)
|
||||
{
|
||||
int numOccurance = 0;
|
||||
int iterable = 0;
|
||||
int consecutiveFourDetected = 0;
|
||||
for (int i = 0; i < values.length - 1; i++) {
|
||||
if (values[i] == values[iterable]) {
|
||||
numOccurance++;
|
||||
if (i != 0) {
|
||||
iterable++;
|
||||
}
|
||||
} else {
|
||||
numOccurance = 0;
|
||||
}
|
||||
if (numOccurance >= 4) {
|
||||
consecutiveFourDetected++;
|
||||
}
|
||||
|
||||
}
|
||||
if (consecutiveFourDetected != 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
|
||||
*/
|
||||
|
||||
package com.chloefontenot.exam2_mvn_practice_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Exam2_mvn_Practice_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.exam2_mvn_practice_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class PrintArrayReversedEven {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
printRE(new int[] {1, 2, 3});
|
||||
printRE(new int[2]);
|
||||
printRE(new int[] {2, 4, 7, 8});
|
||||
}
|
||||
public static void printRE(int[] array) {
|
||||
int arrayLength = 0;
|
||||
for (int i = 0; i <= array.length - 1; i++) {
|
||||
// determine array length.
|
||||
if (array[i] % 2 == 0) {
|
||||
arrayLength++;
|
||||
}
|
||||
}
|
||||
// Now create the return array.
|
||||
int[] returnArray = new int[arrayLength];
|
||||
int arrayI = 0;
|
||||
for (int i = 0; i <= array.length - 1; i++) {
|
||||
if (array[i] % 2 == 0) {
|
||||
// Add even numbers to array.
|
||||
returnArray[arrayI] = array[i];
|
||||
arrayI++;
|
||||
}
|
||||
}
|
||||
// Reverse items in the array.
|
||||
int[] reversedReturnArray = new int[arrayI];
|
||||
int reverseArrayIterable = arrayI - 1;
|
||||
for (int i = 0; i <= returnArray.length - 1; i++) {
|
||||
reversedReturnArray[reverseArrayIterable] = returnArray[i];
|
||||
reverseArrayIterable--;
|
||||
}
|
||||
// Now print the array.
|
||||
for (int i = 0; i <= reversedReturnArray.length - 1; i++) {
|
||||
System.out.print(reversedReturnArray[i] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.exam2_mvn_practice_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class SortCharsInString {
|
||||
|
||||
public static String sort(String s)
|
||||
{
|
||||
// Read string chars, and sort them
|
||||
char array[] = s.toCharArray();
|
||||
char temp;
|
||||
int i = 0;
|
||||
while (i < array.length) {
|
||||
int j = i + 1;
|
||||
while (j < array.length) {
|
||||
// Compare each char, if one is larger, swap them
|
||||
if (array[j] < array[i]) {
|
||||
temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
j += 1;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// Rebuild string
|
||||
String rebuiltString = "";
|
||||
for (char charInArray : array) {
|
||||
rebuiltString += charInArray;
|
||||
}
|
||||
return rebuiltString;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
System.out.print("Enter a string: ");
|
||||
String s = input.nextLine();
|
||||
System.out.println("Sorted string is " + sort(s));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user