Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lets say that I want the program to read command line arguments. compile: javac

ID: 3619496 • Letter: L

Question

Lets say that I want the program to read command line arguments. compile: javac alw.java run: java alw a6p1 encrypt "cat" "the red fox"                   args[0] args[1] args[2] args [3]    is        is         is          is a6p1 encrypt    "cat"       "the red fox" MY PROGRAM CANNOT RECOGNIZE THE "ARGUMENTS"! PLEASE HELP
import java.util.Scanner;
public class alw
{
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);
String message = args[2]; //this should be "cat"
String keyOrEncrypt = args[3]; // this should be "the red fox"
char[] array = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'0','1','2','3','4','5','6','7','8','9',' ',',','.','!','?',']','[','*'};
if (args.length == 0)
{
System.out.println("Put some input after the name of the program.");
}
else if (args[1] == "encrypt") // why can't java understand this?
{
Encrypt(console,array,message,keyOrEncrypt);
}
//if(args[1] == "decrypt")
//{
// Decrypt(console,array);
//}
}

public static void Encrypt(Scanner sc , char[] ar,String word,String key)
{


int difference = word.length() - key.length();
for(int z = 0 ; z < difference ; z++)
{
key += key.charAt(z);
}
System.out.println(key);// where is my output?
System.out.println(word); //where is my output?
}



}





Lets say that I want the program to read command line arguments. compile: javac alw.java run: java alw a6p1 encrypt "cat" "the red fox"                   args[0] args[1] args[2] args [3]    is        is         is          is a6p1 encrypt    "cat"       "the red fox" MY PROGRAM CANNOT RECOGNIZE THE "ARGUMENTS"! PLEASE HELP

Explanation / Answer

Your problem is that you are comparing strings with == This cannot be done in Java You need to use the .equals() method, so your comparison in the if statement should be: else if(args[1].equals("/"encrypt/"") you need /" because the quotation mark is included in the string inputted