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
}```

2. ## 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

3. ## Re: Monotonic Function ?

after many work and debugging it fixed ! ...

4. ## Re: Monotonic Function ?

My remark in my previous reply still stands.

kind regards,

Jos

#### Posting Permissions

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