Online Programming Server

Login

Login with facebook [?]

Facebook

Tutorial 56: CSC1130S - Lecture 7b: Character and switch

You are here: Tutorials >> Basic >> Java >> Introduction to Computing Using Java >> CSC1130S - Lecture 7b: Character and switch

Tutorial ID56
TitleCSC1130S - Lecture 7b: Character and switch

Successive else-if’s

char grade = 'C';
double GPA;
if (grade == 'A')	GPA = 4.0;
else if (grade == 'B')	GPA = 3.0;
else if (grade == 'C')	GPA = 2.0;
else if (grade == 'D')	GPA = 1.0;
else			GPA = 0.0;
  • Very cumbersome!

Post Your Comment

Title
Message