3

To count the number of java terms

 2 years ago
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

advertisements

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?

I am trying to count the number of matched terms from an input list containing one term per line with a data file and create an output file containing both the matched (grep'd) term with the number of matched terms and where there isn't match, to ret

Count the number of Java recursive calls

So I'm a little new to Java and am currently taking a CS intro class at uni. I have a little question that's been bugging me for quite a while. I have a to write a recursive method that "decompresses" the input text using the a "Run-length

Count the number of lines of a file in java, using a random access file

Is there a way to count the number of lines in a file, in java, if the file was declared as a random access file? I was thinking of sth like: while(stop_condition) {String str=file.readLine(); count++; } But i can't find in the random access file doc

How do I count the number of times a sequence occurs in a Java string?

I have a String that looks like: "Hello my is Joeseph. It is very nice to meet you. What a wonderful day it is!". I want to count the number of times is is in the string. How can I do this in Java? int index = input.indexOf("is"); int

How do I count the number of parentheses in a string in a Java regex

So I'm trying to count the number of parentheses (e.g. close brackets) in a string by using a regex. I found this method "groupCount" on the matcher class. So I thought this could help me out. groupCount says in the JavaDoc "Any non-negativ

Get keyboard input and count the number of letters, numbers and spaces in java

How to write a java program to get a string as a key board input. Then count the number of letters, digits and spaces available in that string and display the count of letters, digits and spaces.This is honestly... really, really easy and something t

by counting the number of lines in a text file (java)

Below is how i count the number of lines in a text file. Just wondering is there any other methods of doing this? while(inputFile.hasNext()) { a++; inputFile.nextLine(); } inputFile.close(); I'm trying to input data into an array, i don't want to rea

Count the number of pages in the tiff file using java

How can i count the number of pages in tiff file? i get it as byte array ThanksYou can get the number of pages using the Java Advanced Imaging API. I.e. Using: ImageDecoder.getNumPages() An example of how to use it can be found here.

Count the number of files in a directory using Java

How do I count the number of files in a directory using Java ? For simplicity, lets assume that the directory doesn't have any sub-directories. I know the standard method of : new File(<directory path>).listFiles().length But this will effectively g

Count the number of spaces before the index in Java

I am dealing with long strings, and they will have a certain number of spaces in places in the middle. I know what the index of the beginning letter of the word after the space, how can i count the number of spaces that come before that index in java

How do you recursively count the number of negative numbers in an array (Java)?

I need to use this method: public static int countNegative(double[] numbers, int count){ } to count the number of negative numbers in a double array. I could easily do it if I could include a 3rd parameter, sum, but I can only use the array and an in

How to use Scanner in java to count the number of words separated by & ldquo; & rdquo; from an input .txt file?

My input file look like this: 1,2,3,4,5,6 3,4,5,6,7,8 5,6,7,8,9,9 1,2,3,4,5,6 I want to count the number of word in a column and the number of rows so that I can know the array size and put them into a 2D array. How can I get the number of column and

How to count the number of characters in a string

This question already has an answer here: Java: How do I count the number of occurrences of a char in a String? 40 answers I am trying to count the amount of 'x' characters that are in a string, and print out the number. I end up just counting the nu

Count the number of times a character set appears in a file without BufferedReader

I am trying to count the number of times a string appears in a file. I want to find the number of times that "A, E, I, O, U" appears exactly in that order. Here is the text file: AEIOU aeiou baeiboeu bbbaaaaaa beaeiou caeuoi ajejijoju aeioo aeiO

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK