vendredi 5 juin 2020

Sorting Input Numbers

I am very new to Java and am trying to write an algorithm to take in three numbers and sort them as a way of practicing algorithm writing. Below is what I have.

package com.company;

public class Sort {
    public static void main(String[] args) {
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        int c = Integer.parseInt(args[2]);
        int min, med, max;
    if(Math.max(a, b) == a){
        if(Math.max(a, c) == a){
            max=a;
            if(Math.max(b,c)==b){
                med=b;
                min=c;
            }else{
                med=c;
                min=b;
            }
        }else{
            max=c;
            med=a;
            min=b;
        }
    }else {
        if(Math.max(b,c)==b) {
            max = b;
            if(Math.max(a,c)==a) {
                med = a;
                min = c;
            }else {
                med = c;
                min = a;
            }
        }else{
            max=c;
            med=b;
            min=a;
            }
        }
    }
    }

When I attempt to call this file from the terminal like below I get the following error. What is causing the invalid flag error?

javac Sort.java 1 2 3
error: invalid flag: 1
Usage: javac <options> <source files>
use --help for a list of possible options

Aucun commentaire:

Enregistrer un commentaire