Is there a way to get the tens value from a number without condition statements?
You can use the remainder operator:
int number = 345;
int tens = (number / 10) % 10;
So 345 / 10
== 34
, and 34 % 10
= 4
.
Try it online
How to determine the tens digit of a number in C++
For a non-negative integer x the tens digit is (x / 10) % 10
.
Related Topics
Javax.Net.Ssl.Sslexception: Certificate Doesn't Match Any of the Subject Alternative Names
Passing Data into HTML from Java Via Spring
Sharing a Variable Between Multiple Different Threads
Automatically Convert Style Sheets to Inline Style
Recyclerview Not Calling Oncreateviewholder or Onbindview
Maven- Not Downloading New Added Dependency in Pom.Xml File
How to Override Spring Data JPA Repository Base Methods
I Want to Execute Code Every X Seconds, But Handler.Postdelayed Not Working
Spring Data Query Method With Optional @Param
Java H2 In-Memory Database Error: Table Not Found
Java Nullpointerexception When Adding to Arraylist
How to Store Original Date/Time Without Timezone Calculation to Mongodb
Handling the Null Value from a Resultset
Delete Not Working in Hibernate/Spring Data
Jackson Serializes a Zoneddatetime Wrongly in Spring Boot
Maven: Best Way of Linking Custom External Jar to My Project