1 / 28

Pert 4: Control Structure

Pert 4: Control Structure. Tujuan. Memahami struktur kontrol program Dapat menerapkan: If While Do while For Dalam pembuatan program sederhana. Materi Hari ini.

chaka
Download Presentation

Pert 4: Control Structure

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. Pert 4: Control Structure

  2. Tujuan • Memahami struktur kontrol program • Dapat menerapkan: • If • While • Do while • For Dalam pembuatan program sederhana

  3. Materi Hari ini

  4. A control statement in a programming language is a statement that allows thecompiler to alter its normal execution of line-by-line execution of code.

  5. Mengenal Boolean 16>10 16<10 boolean benar=true; boolean lulus=false;

  6. Model Keputusan I Decision Option 2 Option 1 Outcome 1 Outcome 2

  7. Heads or TailsAnother example of a decision is the one involved in ‘‘heads you win, tails youlose.’’ If you flip a coin and the head appears, then you have won. The otheroption is that the tail appears and you have lost.

  8. How to Spend Allowance If you spend it on ashirt you like, you will not have money for a CD. So you must make a decision.

  9. Terdapat dua option (pilihan), jika nilai>=60 maka akan dicetak “Lulus”, dan jika nilai kurang dari 65 maka dicetak “Tidak Lulus” Int nilai=60 nilai>=65 No Print “Tidak Lulus” Yes Ternyata nilai=60 maka pilihan yang ada akan jatuh pada Option 2, maka akan dicetak “Tidak Lulus” Print “Lulus”

  10. Model Keputusan II Option 2 has no outcome Decision Option 1 Outcome 1

  11. Terdapat dua option (pilihan), jika nilai>=60 maka akan dicetak “Lulus”, dan jika nilai kurang dari 65 maka dicetak “Tidak Lulus” Int nilai=60 nilai>=65 Ternyata nilai=60 maka pilihan yang ada akan jatuh pada Option 2, tapi option 2 tidak ada outcome Yes Print “Lulus”

  12. Statemen if When you buy an item from an online vendor, a $5.00 shipping fee is waived for purchases of $25.00 or more. Problem Statement Write a program that calculates the fi nal cost of an item, includingsales tax and shipping, if applicable. Sales tax is 8% of the purchase price.

  13. Output sale < 25.0 total SHIPPING_FEE; System.out.println("Shipping is $5.00");

  14. Nilai boolean True False if (kondisi pilihan){ //statemen ketika kondisi true } int jumlah=100; if(jumlah>50){ System.out.println(“Lebih dari 50”); }

  15. Examples • If amount of the check is less than the balance, boolean expression • subtract the amount of the check from the balance. conclusion • If password entered at the keyboard is the same as the true password, boolean expression • provide access to the account. conclusion • If your age is greater than 16, boolean expression • apply for your driver’s license. conclusion

  16. A loop around a horse’s neck, a circus ring, and a loop around the thoughts in a cartoon character’shead are all shown.

  17. A loop brings to mind a circular image. a part of a program that you execute over and over again until you are permitted to leave that part to getto another programming statement

  18. A person drives a car back home (‘‘loops back’’) to pick up a friend who is standing next to the house

  19. In a program, a loop describes a group of one or more lines of code that must be repeated some number of times

  20. Computers, unlike humans, are tireless, experiencing neither boredom nor fatigue. Repeatingan operation millions of times presents no problem to a computer with an internal clock that ticks billions of times every second

  21. Loop

  22. While Ekpresii Boolean (kondisi) False True Statement 1 Statement 2 Statement n Statement after loop

  23. Example while loop

  24. Problem Statement Write a program that sums a list of integers supplied by a user. The list can be of any size. The program should prompt the user for the number of data. • Java Solution The following application utilizes three variables: size, sum, and count . • size is the number of data; • sum holds a running sum of the numbers supplied by the user so that each time the • user enters a number, that number is added to sum ; and • count keeps track of the number of data. Variables sum and count are initialized to 0; the value of size is supplied by the user.The addition is accomplished using a while loop similar to the loop in the segment that precedes this example.

  25. 0 21 0 5 12 0 3 0 2 1 3 3 3 3 size size size size size sum sum sum sum sum count count count count count

More Related