[Solved] The shortest java code [closed]

[ad_1] Almost correct: System.out.println((int)Math.signum(input.nextInt() – input.nextInt()); “Almost” due to possible integer overlow. Also your longer code might actually be faster (signum() operaton on floating-point numbers), not to mention more readable. 1 [ad_2] solved The shortest java code [closed]

[Solved] how to solve this type of compilation error?

[ad_1] Make all of your fields static if you are just calling them from the Main class. You can’t call an instance field from a static position, as you aren’t currently in an instance. If you wish to keep them non-static, you have to make an instance of DjPageDownloader by putting it in a constructor, … Read more

[Solved] How to get output with println()

[ad_1] If you want to use 0 and 1, here you go: Scanner scanner = new Scanner(System.in); boolean p = scanner.nextInt() != 0; boolean q = scanner.nextInt() != 0; boolean r1 = p && q; boolean r2 = q == r1; boolean r3 = p == r2; System.out.println(r3 ? 1 : 0); [ad_2] solved How … Read more

[Solved] Split the number on a decimal

[ad_1] public static void main(String[] args) { String str = “154.232”; str = str.replaceAll(“\\..*”, “”); System.out.println(str); } or str.substring(0, str.indexOf(“.”)); or // check for index of . is not -1, then do following. str.split(“.”)[0]; output 154 [ad_2] solved Split the number on a decimal

[Solved] Which of the following classes in java library do not implement a design pattern?

[ad_1] The official source for the Java standard library is the standard Java API documentation. And one notable source for design patterns is the book Design Patterns: Elements of Reusable Object-Oriented Software. To begin with, when you look at the options, the question (as quoted in your post) is badly formulated: “Which of the following … Read more

[Solved] Sort the arraylist with date, which is in string format [duplicate]

[ad_1] You must use Collections.sort() method and pass the list as argument. The list will be ordered according to the natural ordering of its element. You can have more info here: http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html [ad_2] solved Sort the arraylist with date, which is in string format [duplicate]

[Solved] Rearrange the string

[ad_1] Before you do sss+=str;,please add sss=str;. you forget to update your sss. public static void main(String[] args) { String s = “2a[2b[c]]]”; Stack s1 = new Stack(); for(int i=0;i<s.length();i++) { s1.push(s.charAt(i)); } String str=””; String sss=””; for(int j=0;j<s.length();j++) { char a = (char)s1.pop(); System.out.println(“a:”+a); // if(a == ”) if((int)a >=49 && (int)a<=58){ for(int i=0;i<(int)a-48;i++){ … Read more

[Solved] Program is saying all my valid inputs are invalid (REGEX code Issue maybe?) [closed]

[ad_1] I think you need to add Pattern. import java.util.*; public class lab2q2 { public static void main(String[] args) { String RegularExp = “((Mr|Ms))?[A-Z][a-z]+([A-Z]([a-z]+\\.))?([A-Z](a-z)+)”; Pattern pattern = Pattern.compile(RegularExp); Scanner keyboard = new Scanner(System.in); for(int i = 0; i< 11; i++) { System.out.println(“Please enter a name: “); String inputString = keyboard.nextLine(); Matcher matcher = pattern.matcher(inputString ); … Read more