Reset author name to chosen name ✨
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class ConditionalOperator1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
System.out.print("please enter an even number: ");
|
||||
int number = scan.nextInt();
|
||||
if ( number % 2 == 0 )
|
||||
System.out.print("\n" + number + " fufills the request!");
|
||||
else
|
||||
System.out.print("\n" + number + " does not fufill the request!");
|
||||
|
||||
System.out.println(number % 2 == 0 ? " yes sir!" : " no sir!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class ConditionalOperator2 {
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
double x = input.nextDouble();
|
||||
double y = input.nextDouble();
|
||||
double z = input.nextDouble();
|
||||
System.out.println((x < y && y < z) ? "sorted" : "not sorted");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class ConditionalOperator3 {
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
double x = input.nextDouble();
|
||||
double y = input.nextDouble();
|
||||
double z = input.nextDouble();
|
||||
System.out.println((x < y && y < z) ? 100 : 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class ConditionalOperator4 {
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
System.out.print("please enter an even number: ");
|
||||
int number = scan.nextInt();
|
||||
System.out.print("\n" + number + ( number % 2 == 0 ? " fufills the request!" : " does not fufill the request!"));
|
||||
|
||||
if (number % 2 == 0)
|
||||
System.out.println(" yes sir!");
|
||||
else
|
||||
System.out.println(" no sir!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class DecimalToHex1 {
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int inputDecimal,
|
||||
outputHex = 0x0;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a decimal value (0-15): ");
|
||||
inputDecimal = input.nextInt();
|
||||
|
||||
// Switch moment
|
||||
switch (inputDecimal) {
|
||||
case 0:
|
||||
outputHex = 0x0; break;
|
||||
case 1:
|
||||
outputHex = 0x1; break;
|
||||
case 2:
|
||||
outputHex = 0x2; break;
|
||||
case 3:
|
||||
outputHex = 0x3; break;
|
||||
case 4:
|
||||
outputHex = 0x4; break;
|
||||
case 5:
|
||||
outputHex = 0x5; break;
|
||||
case 6:
|
||||
outputHex = 0x6; break;
|
||||
case 7:
|
||||
outputHex = 0x7; break;
|
||||
case 8:
|
||||
outputHex = 0x8; break;
|
||||
case 9:
|
||||
outputHex = 0x9; break;
|
||||
case 10:
|
||||
outputHex = 0xA; break;
|
||||
case 11:
|
||||
outputHex = 0xB; break;
|
||||
case 12:
|
||||
outputHex = 0xC; break;
|
||||
case 13:
|
||||
outputHex = 0xD; break;
|
||||
case 14:
|
||||
outputHex = 0xE; break;
|
||||
case 15:
|
||||
outputHex = 0xF; break;
|
||||
|
||||
}
|
||||
|
||||
// Output
|
||||
System.out.println("The hex value is " + String.format("%x", outputHex));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class DecimalToHex2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int inputDecimal,
|
||||
outputHex = 0x0;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a decimal value (0-15): ");
|
||||
inputDecimal = input.nextInt();
|
||||
|
||||
// Switch moment
|
||||
if (inputDecimal == 0) {
|
||||
outputHex = 0x0;
|
||||
} else if (inputDecimal == 1) {
|
||||
outputHex = 0x1;
|
||||
} else if (inputDecimal == 2) {
|
||||
outputHex = 0x2;
|
||||
} else if (inputDecimal == 3) {
|
||||
outputHex = 0x3;
|
||||
} else if (inputDecimal == 4) {
|
||||
outputHex = 0x4;
|
||||
} else if (inputDecimal == 5) {
|
||||
outputHex = 0x5;
|
||||
} else if (inputDecimal == 6) {
|
||||
outputHex = 0x6;
|
||||
} else if (inputDecimal == 7) {
|
||||
outputHex = 0x7;
|
||||
} else if (inputDecimal == 8) {
|
||||
outputHex = 0x8;
|
||||
} else if (inputDecimal == 9) {
|
||||
outputHex = 0x9;
|
||||
} else if (inputDecimal == 10) {
|
||||
outputHex = 0xA;
|
||||
} else if (inputDecimal == 11) {
|
||||
outputHex = 0xB;
|
||||
} else if (inputDecimal == 12) {
|
||||
outputHex = 0xC;
|
||||
} else if (inputDecimal == 13) {
|
||||
outputHex = 0xD;
|
||||
} else if (inputDecimal == 14) {
|
||||
outputHex = 0xE;
|
||||
} else if (inputDecimal == 15) {
|
||||
outputHex = 0xF;
|
||||
}
|
||||
|
||||
// Output
|
||||
System.out.println("The hex value is " + String.format("%x", outputHex));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Lab8_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Switch1 {
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
System.out.print("Enter a year to tell you a Chinese joke: ");
|
||||
int year = input.nextInt();
|
||||
|
||||
switch (year % 12) {
|
||||
case 0: System.out.println("monkey"); break;
|
||||
case 1: System.out.println("rooster"); break;
|
||||
case 2: System.out.println("dog"); break;
|
||||
case 3: System.out.println("pig"); break;
|
||||
case 4: System.out.println("rat"); break;
|
||||
case 5: System.out.println("ox"); break;
|
||||
case 6: System.out.println("tiger"); break;
|
||||
case 7: System.out.println("rabbit"); break;
|
||||
case 8: System.out.println("dragon"); break;
|
||||
case 9: System.out.println("snake"); break;
|
||||
case 10: System.out.println("horse"); break;
|
||||
case 11: System.out.println("sheep"); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Switch1ConvertedToIfElse {
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
System.out.print("Enter a year to tell you a Chinese joke: ");
|
||||
int year = input.nextInt();
|
||||
|
||||
if (year == 0)
|
||||
System.out.println("monkey");
|
||||
else if (year == 1)
|
||||
System.out.println("rooster");
|
||||
else if (year == 2)
|
||||
System.out.println("dog");
|
||||
else if (year == 3)
|
||||
System.out.println("pig");
|
||||
else if (year == 4)
|
||||
System.out.println("rat");
|
||||
else if (year == 5)
|
||||
System.out.println("ox");
|
||||
else if (year == 6)
|
||||
System.out.println("tiger");
|
||||
else if (year == 7)
|
||||
System.out.println("rabbit");
|
||||
else if (year == 8)
|
||||
System.out.println("dragon");
|
||||
else if (year == 9)
|
||||
System.out.println("snake");
|
||||
else if (year == 10)
|
||||
System.out.println("horse");
|
||||
else if (year == 11)
|
||||
System.out.println("sheep");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Switch2 {
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int x = 1, a = 3;
|
||||
switch (a) {
|
||||
case 1: x += 5;
|
||||
case 2: x += 10;
|
||||
case 3: x += 16;
|
||||
case 4: x+= 34;
|
||||
}
|
||||
System.out.println(x + ", " + a);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Switch3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int dayOfWeekInt;
|
||||
String dayOfWeekString = "nullday",
|
||||
ordinal = "0th";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a number that signifies a day of the week: ");
|
||||
dayOfWeekInt = input.nextInt();
|
||||
|
||||
// Switch moment
|
||||
switch (dayOfWeekInt) {
|
||||
case 1:
|
||||
dayOfWeekString = "Sunday";
|
||||
ordinal = "1st";
|
||||
break;
|
||||
case 2:
|
||||
dayOfWeekString = "Monday";
|
||||
ordinal = "2nd";
|
||||
break;
|
||||
case 3:
|
||||
dayOfWeekString = "Tuesday";
|
||||
ordinal = "3rd";
|
||||
break;
|
||||
case 4:
|
||||
dayOfWeekString = "Wednesday";
|
||||
ordinal = "4th";
|
||||
break;
|
||||
case 5:
|
||||
dayOfWeekString = "Thursday";
|
||||
ordinal = "5th";
|
||||
break;
|
||||
case 6:
|
||||
dayOfWeekString = "Friday";
|
||||
ordinal = "6th";
|
||||
break;
|
||||
case 7:
|
||||
dayOfWeekString = "Saturday";
|
||||
ordinal = "7th";
|
||||
break;
|
||||
}
|
||||
// Print output
|
||||
if (dayOfWeekInt > 7)
|
||||
System.out.println("That number is too high.");
|
||||
else
|
||||
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Switch3ConvertedToIfElse {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int dayOfWeekInt;
|
||||
String dayOfWeekString = "nullday",
|
||||
ordinal = "0th";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a number that signifies a day of the week: ");
|
||||
dayOfWeekInt = input.nextInt();
|
||||
|
||||
// No longer Switch moment
|
||||
if (dayOfWeekInt == 1) {
|
||||
dayOfWeekString = "Sunday";
|
||||
ordinal = "1st";
|
||||
} else if (dayOfWeekInt == 2) {
|
||||
dayOfWeekString = "Monday";
|
||||
ordinal = "2nd";
|
||||
} else if (dayOfWeekInt == 3) {
|
||||
dayOfWeekString = "Tuesday";
|
||||
ordinal = "3rd";
|
||||
} else if (dayOfWeekInt == 4) {
|
||||
dayOfWeekString = "Wednesday";
|
||||
ordinal = "4th";
|
||||
} else if (dayOfWeekInt == 5) {
|
||||
dayOfWeekString = "Thursday";
|
||||
ordinal = "5th";
|
||||
} else if (dayOfWeekInt == 6) {
|
||||
dayOfWeekString = "Friday";
|
||||
ordinal = "6th";
|
||||
} else if (dayOfWeekInt == 7) {
|
||||
dayOfWeekString = "Saturday";
|
||||
ordinal = "7th";
|
||||
}
|
||||
|
||||
// Print output
|
||||
if (dayOfWeekInt > 7) {
|
||||
System.out.println("That number is too high.");
|
||||
} else {
|
||||
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.lab8_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Switch4 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
String dayOfWeekString = "Nullday",
|
||||
ordinal = "0th";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a day of the week (Case-Sensitive): ");
|
||||
dayOfWeekString = input.next();
|
||||
|
||||
// Switch moment
|
||||
switch (dayOfWeekString) {
|
||||
case "Sunday":
|
||||
ordinal = "1st";
|
||||
break;
|
||||
case "Monday":
|
||||
ordinal = "2nd";
|
||||
break;
|
||||
case "Tuesday":
|
||||
ordinal = "3rd";
|
||||
break;
|
||||
case "Wednesday":
|
||||
ordinal = "4th";
|
||||
break;
|
||||
case "Thursday":
|
||||
ordinal = "5th";
|
||||
break;
|
||||
case "Friday":
|
||||
ordinal = "6th";
|
||||
break;
|
||||
case "Saturday":
|
||||
ordinal = "7th";
|
||||
break;
|
||||
}
|
||||
// Print output
|
||||
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user