To count the number of java terms
source link: https://www.codesd.com/item/to-count-the-number-of-java-terms.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
To count the number of java terms
Hey guys i'm stuck on count for a for loop... It should be easy, but for some reason i'm over thinking it or something! Any help would be awesome!
i'm trying to get the total number of terms that passed through %2 and print them out, but when i try it my way it does 11223344556677889910 which i thought was weird! all i want to do is get to say (10).
int counter = 0
for (int i = 1; i < 20; i++) {
if (i % 2 == 1) {
counter += 1;
}
System.out.print(counter);
}
output is 112233445566778899
can't use arrays or lists :\
if
condition seems incorrect, try with: (EDIT: start counter
with 1 and move SOP out of for
loop)
int counter = 1
for(int i=1;i<20;i++) {
if (i%2==0) //Match for 2
{
counter+=1;
}
}
System.out.print(counter);
Related Articles
How do I count the number of matched terms and return a value of zero if they do not match?
Count the number of Java recursive calls
Count the number of lines of a file in java, using a random access file
How do I count the number of times a sequence occurs in a Java string?
How do I count the number of parentheses in a string in a Java regex
Get keyboard input and count the number of letters, numbers and spaces in java
by counting the number of lines in a text file (java)
Count the number of pages in the tiff file using java
Count the number of files in a directory using Java
Count the number of spaces before the index in Java
How do you recursively count the number of negative numbers in an array (Java)?
How to use Scanner in java to count the number of words separated by & ldquo; & rdquo; from an input .txt file?
How to count the number of characters in a string
Count the number of times a character set appears in a file without BufferedReader
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK