[Solved] Determine if a number is prime [closed]

Introduction A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Determining if a number is prime is an important problem in mathematics, and there are several methods for solving it. In this article, we will discuss some of the most common methods for determining … Read more

[Solved] return the list with strings with single occurrence [closed]

Something like this… List<String> result = Stream.of(“A”, “A”, “BB”, “C”, “BB”, “D”) .collect(Collectors.groupingBy( Function.identity(), Collectors.counting())) .entrySet() .stream() .filter(x -> x.getValue() == 1L) .map(Entry::getKey).collect(Collectors.toList()); System.out.println(result); // [C, D] 2 solved return the list with strings with single occurrence [closed]

[Solved] ERROR java.lang.ArrayIndexOutOfBoundsException: length=5; index=5

Exception line (java.lang.ArrayIndexOutOfBoundsException: length=5; index=5) clearly mentions that you are Trying to get index=5but the length of the dato is 5(length=5). So, use only proper index i.e. index 0 to 4. OR Make sure that enough indexes exists to access. Note: You have used dato.split(“, “);. Try with dato.split(“,”);. May be the problem is with … Read more

[Solved] Cleaner way to write code snippet

if you’re only comparing a few values then you might as well proceed with the current approach as there is nothing in place to make it shorter. However, if you’re repeating your self many times, then you can create a helper function to do the work for you. i.e static boolean anyMatch(int comparisonValue, int… elements){ … Read more

[Solved] displaying image in java, no main class found [closed]

Want to display Image, try something like this: import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.*; public class ImagePanel extends JPanel{ private BufferedImage bi; public ImagePanel() { try { bi = ImageIO.read(new File(“Your Image Path”)); } catch (IOException ex) { Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex); … Read more

[Solved] I want to find min/max value within for loop [closed]

I think so is easy int [] tabMaxMin = {1, 4, 8, -4, 11, 0}; int max = tabMaxMin[0]; int min = tabMaxMin[0]; for (int i=1; i < tabMaxMin.length; i++) { if(min >= tabMaxMin[i]) min = tabMaxMin[i]; if(max <= tabMaxMin[i]) max = tabMaxMin[i]; } System.out.println(“MAX=” + max); System.out.println(“MIN=” + min); } 0 solved I want … Read more

[Solved] Comparing strings is “1”

A comparison of Strings in Java is done character by character. Each character has a specific ranking to it based on where it appears in the Unicode character table (for this case, we can use ASCII, since it’s English). “1” would be considered less than “7”, as well as “T”. To invoke (place this inside … Read more