1 / 18

Some problems for your consideration

Some problems for your consideration. Variable names. Which of the following may be used as variable names in Java? rate1 1stPlayer myprogram switch long TimeLimit numberOfWindows. Variable names. Can a Java program have two different variables named number and Number ?. Variables.

mdeyoung
Download Presentation

Some problems for your consideration

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. Some problems for your consideration

  2. Variable names • Which of the following may be used as variable names in Java? • rate1 • 1stPlayer • myprogram • switch • long • TimeLimit • numberOfWindows

  3. Variable names • Can a Java program have two different variables named number and Number?

  4. Variables • Give the declaration for two variables called count and distance. count is of type int and is initialized to zero. distance is of type double and is initialized to 1.5.

  5. Expressions • What is the output of the following program lines: double number = (1/3) * 3; System.out.println( "(1/3) * 3 is equal to " + number );

  6. Expressions • What is the output produced by the following code: int result = 11; result = result / 2; System.out.println( "result is " + result );

  7. Output • What is the output produced by the following: String verbPhrase = "is money"; System.out.println( "Time" + verbPhrase );

  8. Output • What is the output of the following: System.out.println( "2 + 2 = " + (2 + 2) ); System.out.println( "2 + 2 = " + 2 + 2 );

  9. Comments • What are the two kinds of comments in Java?

  10. Comments • What is the output produced by the following Java code? System.out.println( "Hello" ); //System.out.print( "Mr. or Ms. " ); System.out.println( "Student" );

  11. Coupons The skeeball machines on the boardwalk in Wildwood output coupons according to how well you play the game. • You can redeem 10 coupons for a candy bar or 3 coupons for a gumball. You prefer candy bars to gumballs. • Write a program that defines a variable initially assigned to the number of coupons you win. Next, the program should output how many candy bars and gumballs you can get if you spend all of your coupons on candy bars first, and any remaining coupons on gumballs.

  12. Strings • What output is produced by the following: String s = "Hello" + "Joe"; System.out.println( s );

  13. Strings • Write Java statements that will cause the following to be written to the screen: One two buckle your shoe. Three four shut the door.

  14. Strings • What is the difference between System.out.println and System.out.print?

  15. Strings • What is the output produced by the following: System.out.println( 2 + " " + 2 ); System.out.println( 2 + 2 );

  16. Sum, difference, and product • Write a program that reads in two integers (typed from the keyboard) and outputs their sum, difference, and product.

  17. The cost of gas • A car is used for commuting. Write a program that takes as input the distance of the commute in miles, the car’s fuel consumption rate in miles per gallon, and the price of a gallon of gas. The program should then output the cost of the commute.

  18. Make change Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and a dollar, in 5-cent increments, and the machine accepts only a single dollar bill to pay for the item. For example, a possible sample dialog might be: Enter price of an item: 45 You bought an item for 45 cents and gave me a dollar so your change is: 2 quarters 0 dimes, and 1 nickel

More Related