80 likes | 181 Views
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 []) {
E N D
CS110 Programming Language I • Lab 4:Control Statements I Computer Science Department Spring 2014
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?
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:
Follow-up Questions and Activities Try to modify the last code from Switch to If statements.
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