HarrJ

Day 06

Feb 6th, 2024 (edited)
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package jtvi2023b8;
  2.  
  3. public class Day06A {
  4.     public static void main(String[] args) {
  5.         int grade = 60;
  6.         String result = "invalid";
  7.        
  8.         // nested if version
  9.         if (grade <= 100) {
  10.             if (grade >= 97) {
  11.                 result = "1.0";
  12.             }
  13.         }
  14.        
  15.         if (grade <= 96 && grade >= 94) {
  16.             result = "1.25";
  17.         } else if (grade <= 93 && grade >= 91) {
  18.             result = "1.50";
  19.         } else if (grade <= 90 && grade >= 88) {
  20.             result = "1.75";
  21.         } else if (grade <= 87 && grade >= 85) {
  22.             result = "2.0";
  23.         } else if (grade <= 84 && grade >= 82) {
  24.             result = "2.25";
  25.         } else if (grade <= 81 && grade >= 79) {
  26.             result = "2.50";
  27.         } else if (grade <= 78 && grade >= 76) {
  28.             result = "2.75";
  29.         } else if (grade == 75) {
  30.             result = "3.0";
  31.         } else if (grade < 75) {
  32.             result = "Failed";
  33.         }
  34.        
  35.         System.out.println(grade + " have a score of " + result);
  36.     }
  37. }
  38.  
  39.  
  40. //-------------------------------------------
  41.  
  42.  
  43. package jtvi2023b8;
  44.  
  45. public class Day06B {
  46.     public static void main(String[] args) {
  47.         double num1 = 32, num2 = 21, result = 0;
  48.         String op = "-";
  49.        
  50.         if (op == "+") {
  51.             result = num1 + num2;
  52.         } else if (op == "-") {
  53.             result = num1 - num2;
  54.         } else if (op == "*") {
  55.             result = num1 * num2;
  56.         }
  57.        
  58.         System.out.println(num1 + op + num2 +" = " + result);
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment