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
javacommand, not thejavaccommand.javacinitially, but yes, for command-line args you need to usejava Sortwithout the.javaextension.javac Sort.javafollowed byjava Sort 1 2 3