15 || decimal < 0) System.out.println("Invalid input"); else if (decimal 1-) System.out.println("The hex value is " + decimal); else System.out.println("The hex value is " + (char)('A' + decimal - 10)); }"> 15 || decimal < 0) System.out.println("Invalid input"); else if (decimal 1-) System.out.println("The hex value is " + decimal); else System.out.println("The hex value is " + (char)('A' + decimal - 10)); }">
Download presentation
Presentation is loading. Please wait.
Published byKathleen Hood Modified over 9 years ago
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/ https://cs110java.wikispaces.com/
3
What is output by the following programs? import java.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): "); int decimal = input.nextInt(); // the user will enter 12 if (decimal > 15 || decimal < 0) System.out.println("Invalid input"); else if (decimal 1-) System.out.println("The hex value is " + decimal); else System.out.println("The hex value is " + (char)('A' + decimal - 10)); }
5
Problem Description Write a program that convert currency from U.S. dollars $ to Saudi riyal SR or vice. Prompt the user to enter 1 to convert from $ to SR 0 to convert from SR and $. Prompt the user to enter the amount to convert it to what she chose Sample output:
6
Code Skelton
7
Follow-up Questions and Activities Try to modify the last code from Switch to If statements.
8
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.