1,105,221 Community Members

Bit Strings in Java

Member Avatar
razakhan
Newbie Poster
1 post since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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
	                 
	        }
	 
	    }
	}
Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article