Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Monotonic Function ?

    i wrote a Monotonic Function but i don't know what sample i should test to find out that my code working good or not! do this code working good?

    Java Code:
    import java.util.Scanner;
    
    
    public class MonotonicStrings {
    	public MonotonicStrings(){
    		int counter=0;
    		Scanner scanner = new Scanner(System.in);
    		String input2 = scanner.nextLine();
    		Scanner scan = new Scanner(input2);
    		
    	
    		while(scan.hasNext()){
    			String input = scan.next();
    
    		String digits = "";
    		String string = "";
    		
    		
    		if(input.length()<=2){
    			++counter;
    		}
    		
    		// in EveryWorld Desperate Digits And Letters
    		for (int i = 0; i < input.length(); i++) {
    			if (Character.isDigit(input.charAt(i))) {
    				digits += input.substring(i, i + 1);
    			} else if (Character.isLetter(input.charAt(i))) {
    				string += input.substring(i, i + 1);
    			} else {
    				
    			}
    		}
    		
    		
    		
    		
    		
    		//Check Conditions
    		int checki=0;
    		int checks=0;
    		for(int i=0;i<input.length();i++){
    			if(Character.isDigit(input.charAt(i))==true){
    			++checki;	
    			}
    			if(Character.isLetter(input.charAt(i))==true){
    				++checks;
    			}
    		}
    		//
    	
    		
    		
    		
    		//Digit & Letter together
    		if(checki>0 && checks>0){
    			
    			int count1=0;
    			int count2=0;
    			int strings=0;
    			int stringn=0;
    			
    			//Letters
    			for (int i = 0; i < string.length() - 1; i++) {
    				 if (i + 1 < string.length() - 1 && string.codePointAt(i) <= string.codePointAt(i + 1)) {
    					++count1;
    					if (count1 == string.length() - 2) 
    						++strings;
    					
    				} else if (i + 1 < string.length() - 1	&& string.codePointAt(i) >= string.codePointAt(i + 1)) {
    					++count2;
    					if (count2 == string.length() - 2) 
    						++stringn;
    					
    				}
    			}
    			
    			
    			int count3 = 0;
    			int count4 = 0;
    			int digitss=0;
    			int digitn=0;
    			//Digits
    			for (int i = 0; i < digits.length() - 1; i++) {
    				if (i + 1 < digits.length() - 1	&& digits.codePointAt(i) <= digits.codePointAt(i + 1)) {
    					++count3;
    					if (count3 == digits.length() - 2) 
    						++digitss;
    					
    				} else if (i + 1 < digits.length() - 1	&& digits.codePointAt(i) >= digits.codePointAt(i + 1)) {
    					++count4;
    					if (count4 == digits.length() - 2) 
    						++digitn;
    					
    				}
    			}
    			
    			
    			if(strings == digitss){
    				++counter;
    			}else if(stringn == digitn){
    				++counter;
    			}
    			
    			
    		
    			
    			
    		///////// Digits & Letter not	
    			
    	}else if(checki<=0 || checks<=0){
    		
    		int count5 = 0;
    		int count6 = 0;
    		for (int i = 0; i < string.length() - 1; i++) {
    			if (i + 1 < string.length() - 1 && string.codePointAt(i) <= string.codePointAt(i + 1)) {
    			++count5;
    			
    			if (count5 == string.length() - 2) 
    				++counter;
    			}else if (i + 1 < string.length() - 1	&& string.codePointAt(i) >= string.codePointAt(i + 1)) {
    			++count6;
    			
    			if (count6 == string.length() - 2) 
    				++counter;
    			}
    
    		}
    	
    	int count7 = 0;
    	int count8 = 0;
    	for (int i = 0; i < digits.length() - 1; i++) {
    		 if (i + 1 < digits.length() - 1	&& digits.codePointAt(i) <= digits.codePointAt(i + 1)) {
    			++count7;
    			if (count7 == digits.length() - 2) 
    				++counter;
    			
    		} else if (i + 1 < digits.length() - 1	&& digits.codePointAt(i) >= digits.codePointAt(i + 1)) {
    			++count8;
    			if (count8 == digits.length() - 2) 
    				++counter;
    				}
    				
    			}
    		}
    		
    		
    		//while } loop
    		
    	}
    			
    		
    		System.out.println(counter);
    		
    		
    		//function
    	}
    		
    		
    	//Class
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Monotonic Function ?

    It would be nice if you told us what a monotonic String is; all we can see is a lot of juggling with characters, a lot of String fiddling with count1, count2, ... count8 sprinkled in all over the place in code that doesn't even compile.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: Monotonic Function ?

    after many work and debugging it fixed ! ...

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Monotonic Function ?

    My remark in my previous reply still stands.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Calling function in Javascript- from other function
    By jdigger in forum New To Java
    Replies: 1
    Last Post: 02-27-2011, 09:00 PM
  2. this() function
    By sung in forum New To Java
    Replies: 6
    Last Post: 01-23-2011, 03:18 AM
  3. Replies: 3
    Last Post: 12-04-2009, 03:08 PM
  4. Need help with get function
    By calicocal in forum New To Java
    Replies: 10
    Last Post: 11-09-2008, 07:59 PM
  5. Need a little help with a function!
    By Nuluvius in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 11:33 PM

Posting Permissions

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