Lab7Methods

Lab7Methods - Lab 7 - Methods Pre-Lab: Tell the output of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 7 - Methods Pre-Lab: Tell the output of the following program. public class WeirdClass { public static void main(String[] args) { int x = 5; int y = 8; int number; firstMethod(x,7); number = secondMethod(y+3); System.out.println("2: "+number); number = thirdMethod(x+y, y-3); System.out.println("3: "+number); } public static void firstMethod(int y, int x) { System.out.println("1: "+y+x); } public static int secondMethod(int z) { return (z*6-2); } public static int thirdMethod(int a, int b) { return (a * b / 5); } } Lab: The program below is all written in the method main. Choose three parts of the program to split out into their own methods. Rewrite the program using those three methods. /* Ages * Author: Dr. Franklin * Purpose: Stores the ages of a group of people. Answers certain types of questions the * user asks. */ import java.util.Scanner; public class Ages { /* main * The main method performs the input and output for the ages program. */ public static void main(String[] args)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 2

Lab7Methods - Lab 7 - Methods Pre-Lab: Tell the output of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online