1 / 8

CS110 Programming Language I Lab 4 : Control Statements I Computer Science Department

CS110 Programming Language I Lab 4 : Control Statements I Computer Science Department Spring 2014. here is the new site: https://cs110java.wikispaces.com/. import java.util.Scanner ; public class lab5_1 {   public static void main(String args []) {

quasar
Download Presentation

CS110 Programming Language I Lab 4 : Control Statements I Computer Science Department

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS110 Programming Language I • Lab 4:Control Statements I Computer Science Department Spring 2014

  2. here is the new site:https://cs110java.wikispaces.com/

  3. importjava.util.Scanner; • public class lab5_1 { •   public static void main(String args[]) { •     Scanner input = new Scanner(System.in); • System.out.print("Enter a decimal value (0 to 15): "); • intdecimal = input.nextInt(); // the user will enter 12 •  if (decimal > 15 || decimal < 0) • System.out.println("Invalid input"); •  else if (decimal < 10 && decimal > 1-) • System.out.println("The hex value is " + decimal); •   else • System.out.println("The hex value is " + (char)('A' + decimal - 10)); •   } • } • What is output by the following programs?

  4. Problem Description • Write a program that convert currency from U.S. dollars $to Saudi riyal SR or vice . Prompt the user to enter 1to convert from $ to SR 0to convert from SR and $. Prompt the user to enter the amount to convert it to what she chose Sample output:

  5. Code Skelton

  6. Follow-up Questions and Activities Try to modify the last code from Switch to If statements.

  7. Evaluation • By using Switch write a program that prompt the user to enter a character between A and C and display the arrangement of this character If the user enter something else print (Invalid input) Sample output: Enter a letter from A to C: C The arrangement of this character is 3

More Related