Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Java Switch Statement

import java.util.Scanner;

public class GradeCalculatorIF
{
   public static void main (String [] args)
   {
       Scanner sc = new Scanner(System.in);

       System.out.println("Please input a student unit total");
       double unitTotal = sc.nextDouble();
       
       if(unitTotal >= 0 && unitTotal < 50)
       {
           System.out.println("F-<m");
       }
       if(unitTotal >= 50 && unitTotal < 60)
       {
           System.out.println("P-5");
       }
       if(unitTotal >= 60 && unitTotal < 70)
       {
           System.out.println("C-6");
       }
       if(unitTotal >= 70 && unitTotal < 80)
       {
           System.out.println("D-7");
       }
       if(unitTotal >= 80 && unitTotal < 90)
       {
           System.out.println("HD-8");
       }
       if(unitTotal >= 90 && unitTotal < 100)
       {
           System.out.println("HD-9");
       }
       if(unitTotal == 100)
       {
           System.out.println("HD-10");
       }
       if(unitTotal > 100 && unitTotal < 0)
       {
           System.out.println("Invalid");
       }
   }
}




How can I change that into a switch statement? Please help a brother out here.
https://www.tutorialspoint.com/java/swit...n_java.htm
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Switches should be used for switching, not condition checking. You are better off using else-if as it is much clearer.
Switches should be used when determining which option from multiple options should be used and should not be used with bool statements.
[email protected]

Discord: Lord_Suspect

[0x01] I do not deal elsewhere, these are my only accounts; confirm on site before conducting business!! [0x02]
You cannot possibly use a switch statement in that. Switch statements check for equivalency and equivalency only.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by AdvmxJan 6, 2017 06:04 PM 3 229 Jan 6, 2017 06:04 PM
Last Post: Sogomn
[Java] by silabgarzaDec 13, 2016 10:43 AM 3 218 Dec 13, 2016 10:43 AM
Last Post: Zhyper
[C] by SureDawggJun 1, 2016 10:16 AM 14 439 Jun 1, 2016 10:16 AM
Last Post: Kantos