1 / 1

DISPLAY "Enter age (zero ends):”

/* Investigate_age.java by Kari Silpiö */ class Investigate_age { public static void main (String[] args) { /* *** DEFINITIONS *** */ int age; int minors = 0; int adults = 0; /* *** LOGICAL PART *** */

kesia
Download Presentation

DISPLAY "Enter age (zero ends):”

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. /* Investigate_age.java by Kari Silpiö */ • class Investigate_age • { • public static void main (String[] args) • { • /* *** DEFINITIONS *** */ • int age; • int minors = 0; • int adults = 0; • /* *** LOGICAL PART *** */ • System.out.print ("Enter age (zero ends ): "); • age = Keyboard.readInt ( ); • while( age > 0 ) • { • if(age < 18) • { • System.out.println ("Minor"); • minors= minors + 1; • } • else • { • System.out.println ("Adult"); • adults = adults + 1; • } • System.out.print ("Enter age (zero ends): "); • age = Keyboard.readInt ( ); • } • System.out.println (minors + " minor(s), " + • adults + " adult(s)"); • } • } DEFINITIONS age N 3 minors N 2 adults N 2 START minors = 0 adults = 0 DISPLAY "Enter age (zero ends):” ACCEPT age age > 0 FALSE TRUE age < 18 FALSE TRUE DISPLAY "Minor" DISPLAY "Adult" minors = minors + 1 adults = adults + 1 DISPLAY "Enter age (zero ends): " ACCEPT age DISPLAY minors " minor(s), " adults " adult(s)." END Kari Silpiö (transl. Birgitta Jansson-Koponen, edited by JV)

More Related