+ 3
How to get first 10 letters of a strings?
I have a string which length is more than 50. I want to show the first 10 letters and ... . How I can implement it.
5 Respostas
+ 17
String str="helloiamGaurav,happynewyear",newstr="";
for(int a=0;a<=9;a++)
newstr+=str.charAt(a);
System.out.print(newstr);
//yes , possibly there are many other possible ways , new methods for that☺
+ 4
@Bharath_Teki u could do this
String s1="TeamA 20";
String s2="TeamB 40";
int newS1=Integer.parseInt(s1.replaceAll("\\D",""));
// using regex to repalace all characters except the numbers
int newS2=Integer.parseInt(s2.replaceAll("\\D",""));
// same here
if(newS1>newS2){
System.out.println("TeamA 20 won");
}
else {
System.out.println("TeamB 40 won");
}
0
@ Gaurav given String s1 = " TeamA 20 TeamB 40";
Based on given string,We have to decided which team won. I know that., parseInt() converts string to integer but I am confused.Help me in logic.