UsingMethodsFinal

UsingMethodsFinal - System.out.println int sum =...

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

View Full Document Right Arrow Icon
// File: UsingMethodsFinal.java // Author: Amber Settle // Purpose: To demonstrate how to use programmer-defined methods // The version of the program that was written during the recording / import java.util.Scanner; i public class UsingMethodsFinal { public static void main(String[] args) { // Print a square with 5 row and 5 columns filled // with asterisks printSquare('*', 5); System.out.println(); // Print a square with 3 rows and 3 columns filled // with question marks printSquare('?', 3); System.out.println(); // Print the sum of 2 squared plus 3 squared System.out.println("2^2 + 3^2 = " + sumOfSquares(2, 3));
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println(); int sum = sumOfSquares(1, 2); System.out.println("1^2 + 2^2 = " + sum); } // closes main // Prints a square filled with the indicated char, // with size rows and size columns public static void printSquare(char symbol, int size) { for (int i = 1; i <= size; i++) { for (int j = 1; j <= size; j++) System.out.print(symbol); System.out.println(); } } // Returns a squared plus b squared (a^2 + b^2) public static int sumOfSquares(int a, int b) { int value = a*a + b*b; return value; } }...
View Full Document

This note was uploaded on 03/05/2011 for the course CSCI 384 taught by Professor Drchan during the Spring '11 term at CA Health Sciences.

Ask a homework question - tutors are online