LinusHuck
LinusHuck
Explore posts from servers
JCHJava Community | Help. Code. Learn.
Created by Pong on 1/28/2025 in #java-help
Tiles in a 2d Java game
should prob look like this then title= new ArrayList<Char>(); title['a'] = ...
26 replies
JCHJava Community | Help. Code. Learn.
Created by Pong on 1/28/2025 in #java-help
Tiles in a 2d Java game
you could use the alphabet
26 replies
JCHJava Community | Help. Code. Learn.
Created by SidKid on 1/27/2025 in #java-help
how to solve this without loops at all
/run
public class A{
public static void main(String[] args){
System.out.println(count("11abc11"));
System.out.println(count("abc11x11x11"));
System.out.println(count("111"));
}

public static int count(String str)
{
if (str.length() < 2)
{
return 0;
}
if (str.startsWith("11"))
{
return 1 + count(str.substring(2));
}
return count(str.substring(1));
}

}
public class A{
public static void main(String[] args){
System.out.println(count("11abc11"));
System.out.println(count("abc11x11x11"));
System.out.println(count("111"));
}

public static int count(String str)
{
if (str.length() < 2)
{
return 0;
}
if (str.startsWith("11"))
{
return 1 + count(str.substring(2));
}
return count(str.substring(1));
}

}
15 replies
JCHJava Community | Help. Code. Learn.
Created by SidKid on 1/27/2025 in #java-help
how to solve this without loops at all
Sure something like this should work
public static int count(String str, String toCount)
{
if (str.length() < toCount.length())
{
return 0;
}
if (str.startsWith(toCount))
{
return 1 + count(str.substring(toCount.length()), toCount);
}
return count(str.substring(1), toCount);
}
public static int count(String str, String toCount)
{
if (str.length() < toCount.length())
{
return 0;
}
if (str.startsWith(toCount))
{
return 1 + count(str.substring(toCount.length()), toCount);
}
return count(str.substring(1), toCount);
}
Should work ig
15 replies
JCHJava Community | Help. Code. Learn.
Created by AyoWut? on 10/6/2024 in #java-help
Creating an object of an entire class?
13 replies
JCHJava Community | Help. Code. Learn.
Created by AyoWut? on 10/6/2024 in #java-help
Creating an object of an entire class?
Since he is at the start of java i would say not also @AllArgsConstructor is a part of lombok https://projectlombok.org/features/
13 replies
JCHJava Community | Help. Code. Learn.
Created by Franscis123$# on 8/5/2024 in #java-help
How to check if a value coincide with any enum value?
mb should have done it in an ide 😄
8 replies
JCHJava Community | Help. Code. Learn.
Created by Franscis123$# on 8/5/2024 in #java-help
How to check if a value coincide with any enum value?
idk what you mean
8 replies
JCHJava Community | Help. Code. Learn.
Created by Franscis123$# on 8/5/2024 in #java-help
How to check if a value coincide with any enum value?
So baiscally you have a string and want the enum value of it if there is one like this
String example = "Alejandra";
String example = "Alejandra";
and then you want the enum value of the string
Names name = Names.valueOf(example);
Names name = Names.valueOf(example);
there you go method
public Names getEnumValue(String input)
{
Names name = Names.valueOf(input);
if(name == null)
{
System.out.println("Invalid name");
return null;
}
else
{
System.out.println("Valid name");
return name;
}
}
public Names getEnumValue(String input)
{
Names name = Names.valueOf(input);
if(name == null)
{
System.out.println("Invalid name");
return null;
}
else
{
System.out.println("Valid name");
return name;
}
}
is also equal to
public Names getEnumValue(String input)
{
Names name = Names.valueOf(input);
if(name == null)
{
System.out.println("Invalid name");
}
else
{
System.out.println("Valid name");
}
return name;
}
public Names getEnumValue(String input)
{
Names name = Names.valueOf(input);
if(name == null)
{
System.out.println("Invalid name");
}
else
{
System.out.println("Valid name");
}
return name;
}
8 replies