i have two numbers...

1564656
1981676
i want to check if the first and the last number from a string of these numbers are the same or not...how would i do that. how would i just compare the first and a last number and ignore the other numbers in this string?

my code so far...

class lotto
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog (null, " LOTTOMAX - PLAY - WIN");
String numgen =JOptionPane.showInputDialog (null, " ENTER 7 DIGIT NUMBER:" );
int playa1 = Integer.parseInt(numgen);
JOptionPane.showMessageDialog (null, playa1);
int LottoRandom = (int)(Math.random()*10000000);
JOptionPane.showMessageDialog (null, LottoRandom);
if (playa1 >10000000 )
{
JOptionPane.showMessageDialog (null, " INVALID NUMBER. ");
}

To compare the first and last numbers in a string, you can follow these steps:

1. Extract the first and last characters from the string.
- You can use the `charAt()` method in Java to get the character at a specific position in a string. In this case, you need the first character (position 0) and the last character (position `length - 1`).
- Use the `length()` method to get the length of the string, and subtract 1 to get the index of the last character.

Here's an example of how you can modify your code to compare the first and last numbers:

```java
import javax.swing.JOptionPane;

class lotto {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "LOTTOMAX - PLAY - WIN");
String numgen = JOptionPane.showInputDialog(null, "ENTER 7 DIGIT NUMBER:");
// Extract first and last characters from the string
char firstChar = numgen.charAt(0);
char lastChar = numgen.charAt(numgen.length() - 1);

// Convert characters to integers
int firstNumber = Character.getNumericValue(firstChar);
int lastNumber = Character.getNumericValue(lastChar);

JOptionPane.showMessageDialog(null, "First Number: " + firstNumber);
JOptionPane.showMessageDialog(null, "Last Number: " + lastNumber);

// Compare the first and last numbers
if (firstNumber == lastNumber) {
JOptionPane.showMessageDialog(null, "The first and last numbers are the same.");
} else {
JOptionPane.showMessageDialog(null, "The first and last numbers are different.");
}
}
}
```

This code will display the first number, last number, and a message indicating whether they are the same or different.