So for an assignment I have to make a programm that asks for a input of a string and then detects palindromes.
thing is, also numbers can be put in. When more than half of the input of the string is a number it needs to regard the string as a numeric string and disregard the other symbols.
So what i thought is to put the input string into an array then look for the numbers (ASCII# between 48 and 57) and count those. Afterwards compare the number of Numbers vs number of Letters and see which one has more.
however, i can't seem to programm the thing that it counts the numbers in a string. can someone help me, i have this already:
public class opgave41 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("input a string:");
String reeks = sc.nextLine();
char[] array1 = reeks.toCharArray();
int numbers;
int other;
for(int i=0;i<array1.length;i++){
if (int array1[i] < 57 || int array1[i] > 48)
numbers++;
else
other++;
}
System.out.prinln(numbers);
System.out.prinln(other);
}
}
if i compile it I get this:
opgave41.java:38: '.class' expected
if (int array1[i] < 57 || int array1[i] > 48)
^
opgave41.java:39: ')' expected
numbers++;
^
2 errors
how can i get this to worK?