# HOW TO FINDING INDEX OF A NUMBER

Page 1 of 1

## 7 Replies - 857 Views - Last Post: 10 March 2020 - 03:12 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=418624&amp;s=92903cb555acaca873762bc26570423e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 supNub

Reputation: 1
• Posts: 11
• Joined: 25-December 19

# HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 10:05 AM

I have project which i need to enter 5 digit number then be able to zero in on all/any of the numbers and check what they are divisible by example below , but i cant zero in on what syntax is should be using

EXAMPLE:
the leftmost digit is divisible by 1 and
the leftmost two digits are divisible by 2 and
the leftmost 3 digits are divisible by 3 and
the leftmost 4 digits are divisible by 4 and
leftmost 5 digits (the five-digit number itself) is divisible by 5.

import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int	numbSize;
int numb;
int	numbLarge=-1;

Scanner myScan = new Scanner(System.in);

System.out.print("Enter  5 digit number: ");
numb = myScan.nextInt();
numbSize = String.valueOf(numb).length();
if (numbSize != 5) {
System.out.println("This is not a 5 digit number");

}

}
}

This post has been edited by modi123_1: 10 March 2020 - 10:50 AM
Reason for edit:: In the future please use the [code] tags in the editor.

Is This A Good Question/Topic? 0

## Replies To: HOW TO FINDING INDEX OF A NUMBER

### #2 NeoTifa

• NeoTifa Codebreaker, the Scourge of Devtester

Reputation: 4655
• Posts: 19,487
• Joined: 24-September 08

## Re: HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 10:15 AM

Try using %. That should give you pretty much all you need.

### #3 supNub

Reputation: 1
• Posts: 11
• Joined: 25-December 19

## Re: HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 10:46 AM

sorry but i am really new to this so im going to need a bit more info can you provide an example of (%) is setup or any more info

### #4 modi123_1

• Suitor #2

Reputation: 15568
• Posts: 62,341
• Joined: 12-June 08

## Re: HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 10:53 AM

% is typically the 'modulus operator'. You should check into that.

ex
https://nullbeans.co...mples-and-uses/

### #5 NeoTifa

• NeoTifa Codebreaker, the Scourge of Devtester

Reputation: 4655
• Posts: 19,487
• Joined: 24-September 08

## Re: HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 11:12 AM

My apologies, I assumed you knew the math operators already, given you knew about Scanners, as those are usually day 1 lessons. X % Y gives the remainder when divided. If the % returns 0, it's perfectly divisible. Ex: 4%2=0, 5%2=1.

### #6 supNub

Reputation: 1
• Posts: 11
• Joined: 25-December 19

## Re: HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 12:06 PM

yes scanner is fun i learned it really quick but i remember covering this but ill have to review it again my next problem is once i place the if statement with (%)operater how do i target the specific number i want

example 12345
how would i check if lets say the 3rd number is divisable

### #7 NeoTifa

• NeoTifa Codebreaker, the Scourge of Devtester

Reputation: 4655
• Posts: 19,487
• Joined: 24-September 08

## Re: HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 02:36 PM

Well, your number is being brought in as a String, which is basically an array of character objects. There is a method called Integer.toInt(String s) that returns the string as a number if you want to go the substring or base 10 division route. Quite a number of ways you could do it. Either way, I'd imagine a for loop would suit your needs. I'm not gonna give you the full logic, as it would defeat the purpose of the exercise, but I think I gave more than enough hints. :)Good luck!

Speaking of base 10 division, remember that dividing an integer by another integer will return an integer, which will drop any remainder if I recall correctly, which could be handy if you don't want to loop.

This post has been edited by NeoTifa: 10 March 2020 - 02:39 PM

### #8 supNub

Reputation: 1
• Posts: 11
• Joined: 25-December 19

## Re: HOW TO FINDING INDEX OF A NUMBER

Posted 10 March 2020 - 03:12 PM

GOT IT THANKS