Results 1 to 3 of 3
  1. #1
    nighteagle2 is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Beginner Java Problem

    Hey Im having trouble on a homework assignment. I'm a noob at java. This is a part of a program that checks your binary number and returns true or false if its correct.

    So I can't get the binCheck =+ k part to work. I want it to only add k to binCheck if the character is a 1, but it seems to do it regardless of the number.

    I really need help.

    Thanks

    Java Code:
    public static boolean checkBin(String bin, int number)
    	{
    		// Sums up binary sequence
    	
    		int numCheck = 0;
    		int m = 0;
    		
    		for(int k = 128; k>=1 && m <= 8; k/=2)
    		{	
    			if (bin.charAt(m) == '1');
    			{
    				numCheck += k;
    			
    			}
    			
    			m++;
    			
    		}
    
    		if (numCheck == number)
    		{
    			return true;
    		}
    		else
    		{
    			return false;
    		}

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Beginner Java Problem

    On line 10 You have ended the if statement with a ;
    remove it so it is like line 20

  3. #3
    nighteagle2 is offline Member
    Join Date
    Feb 2012
    Posts
    8
    Rep Power
    0

    Default Re: Beginner Java Problem

    Hahahah thanks man. I feel so stupid.

Similar Threads

  1. Beginner Java Problem (Running Objects)
    By marcwilliamson_ in forum New To Java
    Replies: 4
    Last Post: 04-24-2011, 06:45 AM
  2. Beginner Java Modding Problem...
    By walkineagle in forum New To Java
    Replies: 3
    Last Post: 04-13-2011, 05:20 AM
  3. Beginner Problem
    By Freakzoyd in forum New To Java
    Replies: 6
    Last Post: 07-20-2010, 02:23 PM
  4. Beginner in Java - need some help
    By ea09530 in forum Advanced Java
    Replies: 4
    Last Post: 04-06-2010, 12:47 AM
  5. Beginner's Problem on Loop/If statement
    By obdi in forum New To Java
    Replies: 2
    Last Post: 07-07-2008, 02:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •