[Solved] using Logback with slf4j [closed]

It’s not entirely clear what you’re asking. SLF4J is a logging API. Log4j and Logback are implementations of that API (Log4j is also a standalone logging framework, of course). Graylog is a log aggregator. If you want to use SLF4J to send logging to Graylog, you will need an implementation that can somehow send log … Read more

[Solved] Is Java String immutable? [duplicate]

Yes, the java string is immutable. In changeString, you are passing in a reference to the string lalala and then you are changing the reference to one that points to lalalaCHANGE!!!. The original string object is not changed, and the reference in main still refers to that original object. If you were to use a … Read more

[Solved] How can I shorten this Java code? [closed]

From just the perspective of “sorting three strings”, you could just need to do three comparisons and lose all those temp variables. public static void stringOrder(String a, String s, String d) { String tmp; if (a.compareTo(s) > 0) { tmp = a; a = s; s = tmp; } if (a.compareTo(d) > 0) { tmp … Read more

[Solved] Scanner not working? [closed]

if (kirill.equals(kirill2)){ kirill is the Scanner object, not the string. Try something like this: Scanner kirill = new Scanner(System.in); String userInput = kirill.next(); if (userInput.equals(“Java”)){ … Also, note that your code will print “yes” if the user types “Java is a programming langauge.” If you only want it to validate with just “Java,” replace next … Read more

[Solved] continuously changing array size [duplicate]

Use ArrayList in place of String[] .. And you can also easily cast ArrayList to String[] for your final output as ArrayList<String> mStringList= new ArrayList<String>(); mStringList.add(“ann”); mStringList.add(“john”); String[] mStringArray = new String[mStringList.size()]; mStringArray = mStringList.toArray(mStringArray); 0 solved continuously changing array size [duplicate]

[Solved] Problems with linked list

You should not create nodes outside of set. When you do c1.insert(n1); at first this code executes if (isEmpty()) { first = r; previousIP = first; IP = previousIP.next; size++; } which is holding in first and previousIP current node, which is node stored also by n1. But when you execute later c1.insert(n2); since c1 … Read more

[Solved] How to add AdMob to the endscreen?

You can add banner ads programmatically and show or hide them in your game’s screens via a listener. Modify your code as follows, make sure you replace “yourAdUnitId” with your real adUnit Id public class MainActivity extends Activity implements MyAdListener{ private GameView gView; AdView adView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gView = new … Read more

[Solved] Calculating the 10001st prime number [closed]

You have three problems with your code: Your code does not test whether 2 is a prime, so you are missing that in your count. You should initialize counter to 0 or 1, not 2. By using while (i<=10001), you are counting until you find 10002 primes. Since you are also not counting 2, you … Read more

[Solved] rounding up a number to nearest 9

You can do: private int getInventorySize(int max) { if (max <= 0) return 9; int quotient = (int)Math.ceil(max / 9.0); return quotient > 5 ? 54: quotient * 9; } Divide the number by 9.0. And taking the ceiling will get you the next integral quotient. If quotient is > 5, then simply return 54, … Read more

[Solved] java sql connections via class

This is pretty awful code – useless as written. You’ve got a lot of work to do. I’d recommend that you study this and throw your code away: package persistence; import java.sql.*; import java.util.*; /** * util.DatabaseUtils * User: Michael * Date: Aug 17, 2010 * Time: 7:58:02 PM */ public class DatabaseUtils { private … Read more

[Solved] Difference between various classes to read a file [closed]

Class DataInputStream A data input stream is use to read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream. Data input streams and data output streams represent Unicode strings in a … Read more