We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,787 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Bit Strings in Java

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
	                 
	        }
	 
	    }
	}
2
Contributors
1
Reply
12 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
razakhan
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0626 seconds using 2.66MB