Logout

Home
Topic 4
Last
Next

Methods With and Without Parameters

 1 
11 public class MethodsUsingParameters {
12 
13     public static void main(String[] args) {
15         Scanner snr = new Scanner(System.in);
16 
17         System.out.println(methodWithReturn());
18         methodWithoutReturn();
19 
20         System.out.println("What is the name of team 1 in this game?");
21         String team1 = snr.nextLine( );
22         System.out.println("How many goals did they score?");
23         int score1 = snr.nextInt( );
24         System.out.println("What is the name of team 2 in this game?");
25         String team2 = snr.nextLine( );
26         System.out.println("How many goals did they score?");
27         int score2 = snr.nextInt( );
28         String winner = calculateWinner(team1, score1, team2, score2);
29         System.out.println("The winner is " + winner + ".");
36     }
37 
38     public static String methodWithReturn() {
39         return "hello world";
40     }
41 
42     public static void methodWithoutReturn(){
43         System.out.println("how are you doing?");
44     }
45 
46     public static String calculateWinner(String team1, int score1, String team2, int score2){
47         String winningTeam = "not set yet";
48         if(score1 > score2){
49             winningTeam = team1;
50         }else{
51             winningTeam = team2;
52         }
53         return winningTeam;
54     }
55 
56 }