[Solved] Formula nested in loop won’t execute properly

[ad_1] First of all, make n and p integers. Secondly n starts at 3 doesn’t it? Third the Pi series is 4.0 (- fraction + fraction)… Finally you can printf using %.*lf to increase/limit the precision of the output. if ( 2 == route ) { printf(“piseries calculator\n”); double pi=4.0; int n,p; printf(“define precision”); scanf(“%d”,&p); … Read more

[Solved] what is the elegant way to convert the datetime to str in one element in python list? [closed]

[ad_1] The one-liner way: import datetime unit[“data”] = [[item.strftime(“%Y-%m-%d %H:%m:%S”) if isinstance(item, datetime.datetime) else item for item in row] for row in unit[“data”]] As far as I’m concerned I’d wrap this in a couple utility functions though: import datetime def format_item(item): if isinstance(item, datetime.datetime): return item.strftime(“%Y-%m-%d %H:%m:%S”) return item def format_row(row): return [format_item(item) for item … Read more

[Solved] How can user input a sequence of numbers into array// Java

[ad_1] This is how you would do it: Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); int[] array = new int[input.length()]; for(int i = 0; i < input.length(); i++){ array[i] = Integer.parseInt(Character.toString(input.charAt(i))); } String.charAt(int position) gets the Character located at a certain position in the String. Character.toString(Characters ch) converts a Character to a String. … Read more

[Solved] Split with specials character and print string value [closed]

[ad_1] Here is my attempt. public static String first_match(String[] str, String toMatch) { boolean match = false; StringBuilder output = new StringBuilder(); for (int i=0; i<str.length; i++) { if (str[i].equals(toMatch)) { match = true; } if (match){ output.append(str[i]); if (i != str.length-1) { output.append(“//”); } } } return output.toString(); } Using the above method for: … Read more

[Solved] how do i create a method that generates a JButton? [closed]

[ad_1] You can of course write a method that creates JButton for you: public JButton createButton(String label, ActionListener listener, int x, int y) { JButton b = new JButton(label); name.addActionListener(listener); name.setBounds(x, y, 150, 50); return b; } and then use the method like this: button19 = createButton(“Toiletsager”, this, 100, 100); You can of course also … Read more

[Solved] How can I compare the current time with a specific time?

[ad_1] Don’t use a label to hold information. Save the date at the moment you set your label’s text, as a Date, into your model (or simply as a property in your view controller.) Then, when you need to tell If the “label time” is before or after 4:00PM, use the Calendar method date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:) to … Read more

[Solved] I’m writing my first ever java program and it’s not compiling for a certain reason [duplicate]

[ad_1] basically the compiler tells you whats wrong. It says, “class main is public, should be declared in a file named main.java”. Java has a naming rule, that a class inside a java file needs to match that file name. Example 1: Filename -> File.java inside that file: public class Main{ … does violate that … Read more