welcome: please sign in
location: attachment:20091105-EsercitazioneFunzioni.txt of InformaticaCDLmatematica

Attachment '20091105-EsercitazioneFunzioni.txt'

Download

   1 // calcolare il max tra 3 numeri usando una funzione
   2 
   3 import java.util.*;
   4 
   5 public class Max {
   6 
   7 	public static int max (int a, int b) {
   8 		if (a > b)
   9 			return a;
  10 		return b;
  11 	}
  12 	
  13 	public static int max (int a, int b, int c) {
  14 		return max (a, max(b,c));
  15 	}
  16 		
  17 	/**
  18 	 * @param args
  19 	 */
  20 	public static void main(String[] args) {
  21 		// TODO Auto-generated method stub
  22 
  23 	System.out.println("Inserire tre numeri interi.");
  24 		
  25 	Scanner input = new Scanner(System.in);
  26 	int x = input.nextInt();
  27 	int y = input.nextInt();
  28 	int z = input.nextInt();
  29 	
  30 	System.out.println("Il max tra i numeri inseriti รจ " + max(x,y,z));
  31 	}
  32 }
  33 
  34 
  35 //////////////////////////////////////////////////////////////////////////////////

Attached Files

You are not allowed to attach a file to this page.