Results 1 to 4 of 4
Thread: Monotonic Function ?
- 10-17-2011, 03:33 PM #1
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 }
- 10-17-2011, 04:08 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-17-2011, 07:07 PM #3
Re: Monotonic Function ?
after many work and debugging it fixed ! ...
- 10-17-2011, 08:44 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Calling function in Javascript- from other function
By jdigger in forum New To JavaReplies: 1Last Post: 02-27-2011, 09:00 PM -
this() function
By sung in forum New To JavaReplies: 6Last Post: 01-23-2011, 03:18 AM -
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM -
Need help with get function
By calicocal in forum New To JavaReplies: 10Last Post: 11-09-2008, 07:59 PM -
Need a little help with a function!
By Nuluvius in forum New To JavaReplies: 3Last Post: 02-07-2008, 11:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks