[Solved] I can’t catch InputMismatchException [closed]

An exception is captured only if the statement that produce the exception is inside a try-catch statement. You need to place int choosenCharacter=scan.nextInt(); inside the try block, and then the exception will be captured by the catch solved I can’t catch InputMismatchException [closed]

[Solved] How to identify objects in array using instanceOf method and for loop [closed]

for(int i = 0; i < myShapes.length; i++) { System.out.print(“Object ” + i + ” is a”); if(myShapes[i] instanceof Rectangle) System.out.print(” rectangle: “); else if(myShapes[i] instanceof Circle) System.out.print(” circle: “); else if(myShapes[i] instanceof Box) System.out.print(” box: “); else if(myShapes[i] instanceof Cylinder) System.out.print(” cylinder: “); System.out.println(myShapes[i].toString()); } 3 solved How to identify objects in array using … Read more

[Solved] string matching using regular expressions in java

I think this one should do the trick: ^(?!000|666|9\d{2})\d{3}-\d{2}-\d{4}$ Edit: I find the negative look-ahead syntax in this thread. Edit 2: Here is a little code snippet for those who want to test it: import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Pattern pattern = Pattern.compile(“^(?!000|666|9\\d{2})\\d{3}-\\d{2}-\\d{4}$”); Scanner … Read more

[Solved] Java File.renamTo not working

first of all, you should use the path separator / . It’s work on Windows, Linux and Mac OS. This is my version of your problem to rename all files into a folder provide. Hope this will help you. I use last JDK version to speed up and reduce the code. public class App { … Read more

[Solved] Unable to parse this kind of string to java [closed]

This is basically a json stirng. Check more about it here: JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition – December … Read more

[Solved] Return link from Hateos

Based on your comments & question for migration this is what I am suggesting: Map<LinkRelation, Optional<Link>> links = new HashMap<LinkRelation, Optional<Link>>(); links.put(IanaLinkRelations.SELF, Optional.of(response.getLink(IanaLinkRelations.SELF))); links.put(IanaLinkRelations.NEXT, Optional.of(response.getLink(IanaLinkRelations.NEXT))); links.put(IanaLinkRelations.PREVIOUS, Optional.of(response.getLink(IanaLinkRelations.PREVIOUS))); …. //calling addLinlk addLink(apmCoreBaseUrl, response, links, IanaLinkRelations.SELF); addLink(apmCoreBaseUrl, response, links, IanaLinkRelations.NEXT); addLink(apmCoreBaseUrl, response, links, IanaLinkRelations.PREVIOUS); And inside addLink: private void addLink(String baseUrl, RegistrationsResource response, Map<LinkRelation, Optional> links, LinkRelation … Read more

[Solved] Display char instead of 0 in 2D Java array

If you want to print hyphens instead of zeroes, then simply print hyphens instead of zeroes. So instead of this: System.out.print(scoreArray[x][y]); you might write this: if(scoreArray[x][y] == 0) System.out.print(“-“); else System.out.print(scoreArray[x][y]); Your question doesn’t include the code that prints the array so I can’t be more specific to your code. 1 solved Display char instead … Read more

[Solved] Displaying a grid as 2 parts in java

Use a JFrame with a BorderLayout. In the BorderLayout.PAGE_START you add a panel with one grid In the BorderLayout.CENTER you add the label In the BorderLayout.PAGE_END you add the second panel. Read the section from the Swing tutorial on How to Use a BorderLayout for more information and working examples. 3 solved Displaying a grid … Read more