Ok, I have to try to read a 10 digit string, then if it is not 10 digits, tell the user it is counterfeit. Then, if it is 10 digits, go through a sequence of things.
Basically something like this:
- initialize vars
- Read the check number
- If not 10 digits, counterfeit.
Else,
for each char in the number {
if (char is zero) zeroCount ++; reset nonZeroCount;
else nonZeroCount++; reset zeroCount;
if (either of the counts exceeds limit) counterfeit! and get out;
}
If (get out prematurely) counterfeit;
Else, OK.
In the 10-digit check number, if there are (a) three or more zeros in succession, and/or (b) four or more non-zero in succession, then the check should be considered counterfeit
So, here's the code I have so far:
import java.util.*;
public class ValidateCheck {
public static void main(String[] args) {
System.out.println("Enter a 10-digit check number:");
Scanner sc = new Scanner (System.in);
String number = sc.next();
int zeroCount = 0, nonZeroCount = 0;
int index = number.length();
if(index!=10)
{
System.out.println("Counterfeit! See Supervisor.");
}
else
{
for(int i=0;i<index;i++)
{
if(number.charAt(i)==0)
{
zeroCount++;
nonZeroCount = 0;
}
else
{
nonZeroCount++;
zeroCount = 0;
}
if (zeroCount >= 3 || nonZeroCount >= 4)
{
System.out.println("Counterfeit! See Supervisor.");
break;
}
else
{
System.out.println("Check Good!");
break;
}
}
}
}
}
Question
LRoling
Ok, I have to try to read a 10 digit string, then if it is not 10 digits, tell the user it is counterfeit. Then, if it is 10 digits, go through a sequence of things.
Basically something like this:
- initialize vars
- Read the check number
- If not 10 digits, counterfeit.
Else,
for each char in the number {
if (char is zero) zeroCount ++; reset nonZeroCount;
else nonZeroCount++; reset zeroCount;
if (either of the counts exceeds limit) counterfeit! and get out;
}
If (get out prematurely) counterfeit;
Else, OK.
In the 10-digit check number, if there are (a) three or more zeros in succession, and/or (b) four or more non-zero in succession, then the check should be considered counterfeit
So, here's the code I have so far:
import java.util.*; public class ValidateCheck { public static void main(String[] args) { System.out.println("Enter a 10-digit check number:"); Scanner sc = new Scanner (System.in); String number = sc.next(); int zeroCount = 0, nonZeroCount = 0; int index = number.length(); if(index!=10) { System.out.println("Counterfeit! See Supervisor."); } else { for(int i=0;i<index;i++) { if(number.charAt(i)==0) { zeroCount++; nonZeroCount = 0; } else { nonZeroCount++; zeroCount = 0; } if (zeroCount >= 3 || nonZeroCount >= 4) { System.out.println("Counterfeit! See Supervisor."); break; } else { System.out.println("Check Good!"); break; } } } } }Any thoughts would be much appreciated.
Link to comment
Share on other sites
18 answers to this question
Recommended Posts