1.11M Members

Bit Strings in Java

 
0
 

Hello.
I was writing a java code for class and I was unable to figure out how strings and sub-strings work. Can anyone provide some insight on the program.
Here is the problem: Given a bit string expression, such as 10110 OR 11101, evaluate it.
Input: Each string represents a bit-string expression with one operator in it. The operators are AND, OR, and NOT. The operands are bit strings, from 1 to 8 bit long. If the expression contains two operands, they will be the same length. Each input must read as a single string. A single blank will separate the operators and operands.
Output: the value of the expression.
My code so far...

import java.util.Scanner;
	import java.io.File;
	import java.io.IOException;
	 
	public class BitStringsClient
	{
	    public static void main(String[] args) throws IOException
	    {
	        //communicating with the data
	        Scanner inFile = new Scanner(new File("BitStrings.txt"));
	         
	        //declare variables
	        String firststr, secondstr = null;
	        int charValue = 0;
	         
	        //process data
	        while(inFile.hasNext())
	        {
	            firststr = inFile.next();
	            if(firststr.equals("NOT"));
	            {
	                secondstr = inFile.nextLine();
	                //for loop to convert bits to their opposite
	                for(int index = 0; index < firststr.length(); index++)
	                {
	                    if()
	                }
	            }
	            //else
	            if(firststr.equals("AND"));
	            {
	                secondstr = inFile.nextLine();
	                //for loop to multiply strings
	                for(int index = 0; index < firststr.length(); index++)
	                    {
	 
	                    }
	            }
	            //else
	            if(firststr.equals("OR"));
	            {
	                secondstr = inFile.nextLine();
	                //for loop to add strings
	                for(int index = 0; index < firststr.length(); index++)
	                    {
	 
	                    }
	            }
	            //else
	                 
	        }
	 
	    }
	}
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article