[Solved] This Java program converts a natural number into a set-theoretic encoding using iteration. Request help/strategies for a recursive solution?

The second helper method isn’t necessary. Here is a shortened version. public class IntToSetNotationRecursive { private static final String openBrace = “{“; private static final String closeBrace = “}”; private static final String separator = “,”; public static void main(String[] args) { for (int i = 0; i < 6; i++) { System.out.println(i + ” … Read more

[Solved] Java pyramid display

static void staircase(int n) { //int n = scanner.nextInt(); int size = n; for (int i = 0; i <= size-1; i++){ for(int j = 5; j > i; j–){ System.out.print(” “); } for(int j = 0; j <= i; j++){ System.out.print(“#”); } System.out.println(); } output would be: # ## ### #### ##### ###### solved … Read more

[Solved] Replace Exact String in Java

You can use: String result = “http://sdsadasd/time/time.jsp?tp=&a”.replaceFirst(“time\\.jsp”, “java.jsp”); Or using the good friend ApacheCommon StringUtils… String result = StringUtils.replaceOnce(“http://sdsadasd/time/time.jsp?tp=&a”, “time.jsp”, “java.jsp”); For example, you can do: public static void main(String[] args) { String result = “http://sdsadasd/time/time.jsp?tp=&a”.replaceFirst(“time\\.jsp”, “java.jsp”); System.out.println(result); } // Print: http://sdsadasd/time/java.jsp?tp=&a 4 solved Replace Exact String in Java

[Solved] can someone help me with my java assignment?

See comments in the code: import java.util.Scanner; public class ParkingCharges { static Scanner input = new Scanner(System.in); static double minimum_fee = 2.0; static double maximum_fee = 10.0; static double extra_per_HourCharge = 0.50; int daily_hours; public static void main(String[] args) { Display(); //as Alexandro Sifuentes Díaz suggested double hoursParked = hoursEntered(); //change if (that runs once) … Read more

[Solved] Java cannot find symbol during compiling

This has to do with the scope of your variable: From Java Language Specification, Section 6.3: The scope of a declaration is the region of the program within which the entity declared by the declaration can be referred to using a simple name, provided it is visible. A declaration is said to be in scope … Read more

[Solved] Split array into subarray java

This should work. As mentioned in the comments. a is not a string but an array. So you need to iterate over it to call the split() method on it’s containing strings String s = “How are you?” String[] a = s.split(“\\s”); for(String s2 : a){ String[] a2 = s2.split(“”); // do your stuff with … Read more

[Solved] Extracting objects from a list by quantity [closed]

If you are using java-8 or later then List<Drink> list = new ArrayList<>(); list.add(new Drink(“coke”, 30)); list.add(new Drink(“fanta”, 10)); list.add(new Drink(“coke”, 5)); list.add(new Drink(“sprite”, 1)); list.add(new Drink(“coke”, 10)); Map<String, Integer> map = list.stream() .collect(Collectors.groupingBy(Drink::getName, Collectors.summingInt(Drink::getAmount))); System.out.println(map); output {sprite=1, coke=45, fanta=10} Collection<Drink> c = list.stream().collect(Collectors.groupingBy(Drink::getName, Collectors.collectingAndThen( Collectors.reducing((Drink a, Drink b) -> { a.setAmount(a.getAmount() + b.getAmount()); return … Read more