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

Write a Java/C/Javascript program that will translate the Little Man Computer\'s

ID: 3879024 • Letter: W

Question

Write a Java/C/Javascript program that will translate the Little Man Computer's instructions from input into machine code output. Please use the LMC Simulator to check your output. The instructions of Little Man Computer are listed above, please review it. Your program need to:

1. Declare an array of two dimensions, 10 rows and 2 columns. Fill the array, the first column would be instruction, the second column will be the machine op code.

2. Take input one line at a time.

3. For each line, read the first three characters.

4. Loop through the array comparing the three characters with the data on the first column

5. get the second column data once you find the match in the first column.

6. Output the matched data.

Explanation / Answer

import java.util.*;
public class Mach
{
public static void main(String args[])
{
String arr[][]=new String[10][2];
String st;
Scanner in=new Scanner(System.in);
int i,j=0;
for(i=0;i<3;i++)
{j=0;
System.out.println("Enter a string");
st=in.nextLine();
  
arr[i][j]=st.substring(0,3);
j++;
System.out.println("Enter a string in three words");
st=in.nextLine();
arr[i][j]=st;
}j=0;
for(i=0;i<3;i++)
{j=0;
if(arr[i][j].equals(arr[i][j+1]))
System.out.println(arr[i][j]);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote