if (grade >= 70){ // condition is only true if a person's grade in the class is over 70%
System.out.print("You have passed the class");
}
if (grade >= 70){ // condition is only true if a person's grade in the class is over 70%
System.out.print("You have passed the class");
}
else if (grade >= 60){
System.out.print("You can pass the class by completing extra credit work");
}
if (grade >= 70){ // condition is only true if a person's grade in the class is over 70%
System.out.print("You have passed the class");
}
else{ // if the person does not earned a passing grade of 70% or above, they have not passed the class
System.out.print("You did not pass the class");
}
if (grade >= 90){ // condition is only true if a person's grade in the class is over 90%
System.out.print("You have earned an A in the class");
}
else if (grade >=80){ // if a person earned a 80% or above but below 90% they earned a B in the class
System.out.print("You have earned a B in the class");
}
else if (grade >=70){ // if a person earned a 70% or above but below 80% they earned a C in the class
System.out.print("You have earned a C in the class");
}
else{ // if a person earned below a 70% in the class, they did not pass the class
System.out.print("You did not pass the class");
}
import java.util.Scanner;
public class GradeSwitch{
public static void main(String[] args){
String grade;
int gradepoint;
System.out.print("Enter your score: \n");
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
System.out.print("Your score is: ");
System.out.print(score + "\n");
int scoremultipleoften = score/10; // int rounds down
// the grade brackets are 10 points each, so we can divide by 10 to find each letter grade
switch(scoremultipleoften){
case 10:
grade = "A+";
gradepoint = 4;
break;
case 9:
grade = "A";
gradepoint = 4;
break;
case 8:
grade = "B";
gradepoint = 3;
break;
case 7:
grade = "C";
gradepoint = 2;
break;
case 6:
grade = "D";
gradepoint = 1;
break;
default:
grade = "F";
gradepoint = 0;
break;
}
System.out.println("The letter grade you earned is a " + grade);
System.out.println("The grade point you earned is a " + gradepoint);
}
}
GradeSwitch.main(null)
import java.util.Scanner;
class Monotonic {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the length for the array: "); // user decides the total length the array
int length = scanner.nextInt();
int [] array = new int [length];
System.out.println("Enter the numbers for the array: "); // user decides the specific numbers to put in the array
for (int i=0; i<length; i++) {
array[i] = scanner.nextInt();
}
System.out.println(Arrays.toString(array));
boolean answer = monotonicchecker(array);
if (answer == true) // if the array is only increasing or decreasing then it is monotonic
System.out.print("Yes, the function is monotonic");
else // if the array is doing both increasing and decreasing then it is not monotonic
System.out.print("No, the function is not monotonic");
}
}
public static boolean monotonicchecker(int array[]){
boolean ascending=false;
boolean descending=false;
for (int i=0; i<array.length-1; i++){
if (array[i]>array[i+1]){
descending=true;
}
else if (array[i]<array[i+1]){
ascending=true;
}
else{
if(descending && !ascending){
ascending=true;
}
else if(ascending && !descending){
descending=true;
}
}
if(ascending && descending){
return false;
}
}
return true;
}
Monotonic.main(null);
import java.util.Scanner;
class Monotonic {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the length for the array: "); // user decides the total length the array
int length = scanner.nextInt();
int [] array = new int [length];
System.out.println("Enter the numbers for the array: "); // user decides the specific numbers to put in the array
for (int i=0; i<length; i++) {
array[i] = scanner.nextInt();
}
System.out.println(Arrays.toString(array));
boolean answer = monotonicchecker(array);
if (answer == true) // if the array is only increasing or decreasing then it is monotonic
System.out.print("Yes, the function is monotonic");
else // if the array is doing both increasing and decreasing then it is not monotonic
System.out.print("No, the function is not monotonic");
}
}
public static boolean monotonicchecker(int array[]){
boolean ascending=false;
boolean descending=false;
for (int i=0; i<array.length-1; i++){
if (!(array[i]<=array[i+1])){ // changed logic to reflect De Morgan's Law
descending=true;
}
else if (!(array[i]>=array[i+1])){ // changed logic to reflect De Morgan's Law
ascending=true;
}
else{
if(descending && !ascending){
ascending=true;
}
else if(ascending && !descending){
descending=true;
}
}
if(!(!ascending || !descending)){ // changed logic to reflect De Morgan's Law
return false;
}
}
return true;
}
Monotonic.main(null);import java.util.Scanner;