Presentation is loading. Please wait.

Presentation is loading. Please wait.

Some problems for your consideration. Variable names Which of the following may be used as variable names in Java? Which of the following may be used.

Similar presentations


Presentation on theme: "Some problems for your consideration. Variable names Which of the following may be used as variable names in Java? Which of the following may be used."— Presentation transcript:

1 Some problems for your consideration

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

3 Variable names Can a Java program have two different variables named number and Number? 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. 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: 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: 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: 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: What is the output of the following: System.out.println( "2 + 2 = " + (2 + 2) ); System.out.println( "2 + 2 = " );

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

10 Comments What is the output produced by the following Java code? 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. 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. 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: 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: 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? What is the difference between System.out.println and System.out.print?

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

16 Sum, difference, and product Write a program that reads in two integers (typed from the keyboard) and outputs their 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. 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


Download ppt "Some problems for your consideration. Variable names Which of the following may be used as variable names in Java? Which of the following may be used."

Similar presentations


Ads by Google