CSC1100-DanO-Homework04(1)-Word (Product Activation Failed) S MAILINGS REVIEW VI
ID: 3601171 • Letter: C
Question
CSC1100-DanO-Homework04(1)-Word (Product Activation Failed) S MAILINGS REVIEW VIEW , 21, 2:. | Emphases Heading 1 Heading 3 Heading3 Heading4||Normal! Strong Paragraph Styles a) Save this document with your name and the homework number somewhere in the file name. b) Type/paste your answers into the document c) Submit this document to the Blackboard item where you downloaded this document. 1) 16 points] Prompt for and read a single upper-case element symbol into char variable sym. Print the corresponding element and atomic number. Print an err message if the symbol is invalid. Write both if statement and switch statemen versions. Element Boron Carbon Fluorine Hydrogen Nitrogen Oxygen Symbol Atomic number if statement switch statementExplanation / Answer
Scanner s= new Scanner(System.in); char sym = s.next().charAt(0);
if(char='B'| char='C'char='F'| char='H'|char='N'| char='O')
{
printf("valid symbol");
}
else
{
printf("symbol inavalid element");
}
switch(sym){
case 1:
if(sym=='B')
System.out.println("atmomic number:",5);
System.out.println("Element:",Boron);
break;
case 2:
if(sym=='C')
System.out.println("atmomic number:",6);
System.out.println("Element:",Carbon);
break;
case 3:
if(sym=='F')
System.out.println("atmomic number:",9);
System.out.println("Element:",Flourine);
break;
case 4:
if(sym=='H')
System.out.println("atmomic number:",1);
System.out.println("Element:",Hydrogen);
break;
if(sym=='N')
System.out.println("atmomic number:",7);
System.out.println("Element:",Nitrogen);
break;
if(sym=='O')
System.out.println("atmomic number:",8);
System.out.println("Element:",Oxygen);
break;
Default:
System.out.println("Invalid Symbol");
break;
}