[Solved] Head&Tails game simulation between 2 players [closed]

This is only 2 players game. So you can simply set Boolean value to switch between players.E.g.Initialize boolean as boolean isPlayer1Chance = true; When after any chance alter value as inside for loop, if(isPlayer1Choice){ //Do player 1 play }else{ //Do Player 2 Play } isPlayer1Choice = !isPlayer1Choice; 2 solved Head&Tails game simulation between 2 players … Read more

[Solved] I am having difficulty with my deal method

There is a lot of things wrong with this code. Your problem is, because you are randoming more and more instead of using te ran variable you declared at the beggining of deal method. After you declared your ran variable, don’t do dealer.nextInt(deck.length), replace it with ran. Your shuffling is not really shuffling, check this: … Read more

[Solved] Crashing android application [duplicate]

public void onClick(View v) { AlertDialog.Builder a_builder = new AlertDialog.Builder(MainActivity.this); a_builder.setCancelable(false); a_builder.setTitle(“Alert !”); a_builder.setMessage(“do you want to call!!!”); a_builder.setPositiveButton(“Yes”, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //handle the permission at start. if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { //permission not granted, ask for permission return; } Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(“tel:0000000000”)); … Read more

[Solved] Java program to find a pallindrome [closed]

boolean isPalindrome(String input) { for (int i=0; i < input.length() / 2; ++i) { if (input.charAt(i) != input.charAt(input.length() – i – 1)) { return false; } } return true; } This solution is self explanatory, the only edge case requiring explanation is what happens for words with an odd number of letters. For an input … Read more

[Solved] Creating triangle in java [closed]

I hope this simple algorithm gives you an idea of how you could solve this problem step by step. int n = 5; // We go line by line for (int line=0; line<n; line++) { // Calculate number of spaces in the line. Number of spaces on the // right hand side is always the … Read more

[Solved] Java – Convert a string of multiple characters to just a string of numbers

Solution: String s = “(1,2)-(45,87)”; String[] splitted = s.replaceFirst(“\\D+”, “”).split(“\\D+”); // Outputs: [1, 2, 45, 87] Explanation: \\D++ – means one or more non-digit characters s.replaceFirst(“\\D+”, “”) – this is needed to avoid storing empty String at the first index of splitted array (if there is a “delimited” at the first index of input String, … Read more

[Solved] Set color of JTable row at runtime

table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if(!isSelected) { //Important check, see comment below! boolean levelBreak = row == 0; if (!levelBreak) { Object prior = table.getValueAt(row – 1, 0); Object current = … Read more

[Solved] counting the number of zeros [closed]

Here you go: char[] numArray = num.toCharArray(); int counter=0; for(int i=0;i<numArray.length;i++) { if(numArray[i]==’0′) { counter++; } if((i==numArray.length-1&&counter>0)||(counter>0&&numArray[i]!=’0′)) { System.out.println(“Number of Zeroes: “+counter); counter=0; } } Some important points: 1) It’s best to use an array of char values here, instead of operating using a double, because a char array can store many more values- the … Read more

[Solved] Add a method to an exited ArrayList

Calling arrValue.get(i) fetches you the object of FuelData class at ith index in the arrValue arraylist. Now, if the method getOdometer() is defined inside FuelData – You should be able to access it using the below statement arrValue.get(i).getOdometer(“value1”, “value2”, “value3”) Make sure getOdometer method returns a string or atleast it returns something. Also, as I … Read more

[Solved] How to run a java applet code

To draw the I love you text you can call: g.drawString(…) method and position it over the T-Shirt. Next to draw a heart shape, you can call the same method using the ASCII’s heart shape: ♥ But be sure to use a nice (big enough) font so it can be visualized correctly, for example: g.setFont(new … Read more