Ex9CrazyControlOneClass

Ex9CrazyControlOneClass - printSomething();

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Example 8: Control Wrap-Up (so far) /* class CrazyControl * Author: Dr. Franklin * Purpose: Challenge your understanding of the control flow of a program, * integer operators, and output statements. */ import java.util.Scanner; public class CrazyControl { public static void main(String args[]) { Scanner input = new Scanner( System.in ); // read from screen int num; System.out.print("Enter a number: "); num = input.nextInt(); System.out.print("\n"); System.out.printf("%d people ",num); if ((num % 2) == 0) System.out.print("embarked "); else System.out.print("set off "); System.out.print("on a journey of ");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printSomething(); System.out.println("proportions."); if (num > 1) System.out.printf("They "); else System.out.printf("He/she "); printSomethingElse(num); System.outprintln("in circles."); } // end of method main public void printSomething(int number) { if (number > 10) System.out.print("epic "); else if (number > 5) System.out.print("moderate "); else System.out.print("pitifully small "); } public void printSomethingElse(int num) { System.out.println("walked . .."); while (num > 0) { System.out.println("and walked. .."); num = num + 1; } } } // end of CrazyControl...
View Full Document

Ask a homework question - tutors are online