So i managed to create this program but im struggling to output the boolean lessThan and greatherThan. I tried to create the strings str1 and str2 and mess around with them but i can’t get it to work. New to java, sorry!
JavaScript
x
public class Task2{
public static void main (String args []){
String str = "abccccc23";
str = pad (str, 10, '*');
System.out.println(str);
System.out.println(str + " {" + timesCharOccures(str, '*') + "}");
//String str1 = "aoallalaal";
//String str2 = "bobob";
//System.out.println("lol" + str1 + str2 );
}
public static String pad(String base, int n, char c){
while (base.length()<n ){
base = base +c;
}
return base;
}
public static int timesCharOccures(String str, char c){
int counter = 0;
for( int i=0; i<str.length(); i++ ) {
if( str.charAt(i) == 'c' ) {
counter++;
}
}
return counter;
}
public static boolean lessThan(String str1, String str2){
{
return str1.to.LowerCase().compareTo(str2.toLowerCase()) <0;
}
}
public static boolean greaterThan(String str1, String str2){
{
return str1.to.LowerCase().compareTo(Str2.toLowerCase()) >0;
}
}
}
Advertisement
Answer
JavaScript
return str1.to.LowerCase().compareTo(str2.toLowerCase()) <0;
Replace str1.to.lowerCase()
the same way you did for str2
… so `str1.toLowerCase()“
JavaScript
return str1.to.LowerCase().compareTo(Str2.toLowerCase()) >0;
Replace Str2
with str2
.. Java
is case sensitive..
That should fix the issue I think you meant when saying “i can’t get it to work“