Question: in JAVA I am trying to see if the digits are last ONLY if there are digits in the first place. If no digits are

in JAVA

I am trying to see if the digits are last ONLY if there are digits in the first place. If no digits are found then it doesn't have to activate at all.

If digits are in the middle = false; (snow2park == false)

if digits are last = true; (snowpark221 == true)

my code: it has flaws and is not even entering into the if statement because it see's it as false

Please only alternate a little bit. Do not use Character.isDigit(). I don't want to add any unneccessary things if possible.

CODE MUST WORK FOR ANY INPUT THAT IS SIMILAR.

import java.util.Scanner;

public static void main(String[] args)

string str = scnr.nextLine();

for (int j = 0; j < str.length(); ++j ) {

if (j == str.length()) { if (str.charAt(j) >= '0' && str.charAt(j) <= '9') { if (j != str.length() - 1) { System.out.println(str.charAt(j) + " digit is not last"); } } }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!