Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mng2023b5;
- import java.util.Scanner;
- public class Day08B {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int grade;
- String txtIfResult;
- System.out.print("Enter Grade: ");
- grade = sc.nextInt();
- //using if statements only
- if (grade >= 91){
- System.out.println("Excellent");
- }
- if (grade >= 81 && grade <= 90) {
- System.out.println("Great");
- }
- if (grade >= 75 && grade <= 80) {
- System.out.println("Passed");
- }
- if (grade < 75) {
- System.out.println("Failed");
- }
- //notes about if only code
- //everyline uses a single sout command
- //its possibly better to just put the value to print and print it later instead
- //now, utilizing if else if
- if (grade > 100) {
- txtIfResult = "grade greater than 100";
- } else if (grade == 100) {
- txtIfResult = "1.0";
- } else if (grade >= 95) {
- txtIfResult = "1.25";
- } else if (grade >= 91) {
- txtIfResult = "1.5";
- } else if (grade >= 86) {
- txtIfResult = "2.0";
- } else if (grade >= 81) {
- txtIfResult = "2.5";
- } else if (grade >= 75) {
- txtIfResult = "3.0";
- } else {
- txtIfResult = "5.0";
- }
- System.out.println(txtIfResult);
- }
- }
- //------------------------------------------
- package mng2023b5;
- import java.util.Scanner;
- public class Day08D {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String colorName, colorGroup;
- System.out.println("Give a color name:");
- colorName = sc.nextLine().toLowerCase();
- // .toLowerCase() para yung mga if statements gagamit
- // na lang ng .equals vs .equalsIgnoreCase
- if (colorName.equals("red")){
- colorGroup = "Primary Color";
- } else if (colorName.equals("blue")){
- colorGroup = "Primary Color";
- } else if (colorName.equals("yellow")){
- colorGroup = "Primary Color";
- } else if (colorName.equals("green")){//secondary color: green, orange, violet
- colorGroup = "Secondary Color";
- } else if (colorName.equals("orange")){
- colorGroup = "Secondary Color";
- } else if (colorName.equals("violet")){
- colorGroup = "Secondary Color";
- } else {
- colorGroup = "not a primary or secondary color";
- }
- System.out.println(colorName + " is a " + colorGroup);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment