Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Don't know what statement to put

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Location
    Seattle, Washington
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Don't know what statement to put

    i need this program to determine and print the number of odd, even, and zero digits in an integer value read from the keyboard. the "int num = " statement has me confused. what do i type next?
    public static void main(String[] args) {
    		Scanner scan = new Scanner(System.in); 
    		System.out.print("Enter a four-digit integer value: "); 
    		String intX = scan.next();  
    		int oddints = 0; 
    		int evenints = 0; 
    		int zeros = 0; 
    		for(int i = 0; i < intX.length(); i++){ 
    			char y = intX.charAt(i); 
    			[U]int num =  ;[/U]
    				if(num == 0) 
    					zeros++; 
    					else if(num%2 == 0) 
    					evenints++; 
    					else 
    					oddints++; 
    		}
    		System.out.println("Number of odd: " + oddints); 
    		System.out.println("Number of even: " + evenints); 
    		System.out.println("Number of zero: " + zeros); 
    		} 
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,139
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: Don't know what statement to put

    What is that statement supposed to do? It looks like part of an assignment statement.
    An assignment statement needs to have a value to the right of the = that is of the same type as the variable to the left of the =.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 03:19 PM
  2. Replacing an If statement with a Switch statement
    By logi in forum Loops & Control Statements
    Replies: 9
    Last Post: February 3rd, 2013, 11:21 PM
  3. Replies: 2
    Last Post: November 18th, 2012, 01:09 PM
  4. How to put a timer?!?
    By mrprogrammer in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 21st, 2012, 10:44 AM
  5. how can i print the out put !
    By Faha in forum Java IDEs
    Replies: 5
    Last Post: December 30th, 2010, 03:41 AM