Character length finding on string [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Can anyone help me to write code that find how many characters string has.

All you need is - int len = yourString.length();

StringUtils should provide you with something that you are looking for:
int count = StringUtils.countMatches("haahaahaa", "a");
System.out.println(count);

Related

I know this may be already answered, but here we go [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
I have to make a massage out of a sentence. from this: "Jutri sem sama" to "ur e aaJtismsm" this.
What method should I use?
String sporocilo= JOptionPane.showInputDialog("Vpiši sporocilo");
int kodirano= sporocilo.length();
System.out.println(sporocilo);
System.out.println(kodirano);
for(int i=0; i<kodirano;i++){
if(sporocilo.length()%2!=0)
System.out.print(sporocilo.indexOf(i));
else
System.out.print(sporocilo.indexOf(i));
}
Like I said, I have to make a new massage out of the old one and I have to mix indekses.

last two occurance of semicolon(;) in given String using Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How do I get the after last two semicolon's occurrences of a string ?
Example:
Mobiles;Students;Test;Yes;1234
The output should be
Yes;1234
Using a regex replacement, we can try:
String input = "Mobiles;Students;Test;Yes;1234";
String output = input.replaceAll("^.*;([^;]+;[^;]+)$", "$1");
System.out.println(output); // Yes;1234

How to generate a random mobile number starts with zero and have 10 digits, that starts with zero? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
My Friend ask me this question and i am posting it here, if you have better approach please share
String getRandomMobileNumber() {
double random = Math.random();
Double randomten = random*1000000000.0;
return "0"+Math.round(randomten);
}
You can use this, see javadoc:
String phoneNumber = "0" + ThreadLocalRandom.current().nextInt(10000000, 99999999);

Java BigInteger OR function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am using Java and have some problems.
I made two BigInteger variables, p and q.
In my code, I want to add if function, like if(p=1 \ q=1).
I tried many ways but there was error. Do you know how to solve this?
Your question is not completely clear, but you need to use the BigInteger.equals() method, as in this example:
if (BigInteger.equals(p, BigInteger.ONE) || BigInteger.equals(q, BigInteger.ONE)) {
// do something
}

how i can make my variable equal any element of my Array? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have
String[] country={"USA","ks a","UK","France"};
I have a variable String z.
I want to say
if(z.equals(any element of my array (USA or ks or France)
but randomly:
if(z.equals(country[i]){
Doing action any code
}
Can anybody help me?
you can use
if ( Arrays.asList(country).contains(z)) {
// your code
}

Categories

Resources