Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

String Day - 05

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

public class Program03 {

public static void main(String[] args) {


String s = "hello everyone";
/*
* System.out.println(s.equals("hello"));
* System.out.println(s.toString());
* System.out.println(s.compareTo("Hello"));
* System.out.println(s.indexOf(’l’));
* System.out.println(s.lastIndexOf(’l’, 500));
* System.out.println(s.length());
*/
for (int i = 0; i < s.length(); i++) {
if (i < 4)
System.out.print(s.charAt(i));
}
System.out.println();
System.out.println(s.substring(1));
System.out.println(s.substring(6, 11));
System.out.println(s.substring(5, 13));
System.out.println(s.substring(4, 14));
// System.out.println(s.substring(-6, 11));
System.out.println(s.indexOf("e", -5));
// System.out.println(s.substring(6, -11));
System.out.println(s.substring(5, 14));

System.out.println(s.substring(5, 6));
System.out.println(s.substring(5,6).isEmpty());

System.out.println(s.substring(5,5).isBlank());
System.out.println(s.substring(5,6).isBlank());

System.out.println(s.startsWith("hello"));
System.out.println(s.endsWith("everyone"));

System.out.println(s.startsWith("h"));
System.out.println(s.endsWith("e"));

System.out.println(s.startsWith("e"));

}
}
___________________________________________________________________________________
__________________________
/*
* Program to read a string from the user
* and find whether the string has
* a substring "everyone" or not
* if it is there display the character "everyone"
* in the case it present in the user passing
* string
*
* InPUT as : everyone
* Output as : everyone word is present
*
* Input as :EveryOne
* Output as : EveryOne word is present
*
* Input as : Hello
* Output as : Everyone word is not present
*
*/

public class Program02 {


public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter th String");
//String everyone;
String s=sc.nextLine();
String s1=s.toLowerCase();
System.out.println(System.identityHashCode(s));
System.out.println(System.identityHashCode(s1));
if( s1.contains("everyone")) {
int start=s1.indexOf("everyone");
int end=start+8;
String everyone=s.substring(start, end);
System.out.println(everyone+" word is present");
}
else {
System.out.println("everyone word is not present");
}
}
}
_____________________________________________________________________________
Task:

Que- Write a java program to take the file name as argument,if it is a text file
print the file is text file ,else print file is not a text file.

Sample Input : Abc.txt


Output : Abc.txt is a text file

Sample Input : Abc.html


Ouput : Abc.gtml is not a text file

Note: What form user will pass the value as ABC.txt or abc.txt
in that form only return the result to the user.
-------------------------------------------------------------------
Que- Write a program to take array of file name as fileName ,
return an array which have only the file name as text filename

Sample Input : {abc.txt, abc.html , abc.doc, xyz.txt , def.html}


output : {abc.txt, xyz.txt}
-------------------------------------------------------------------
Que- Write a program by creating a method which will take the argument
as String Object and print the requirement in below form :

> Print the length of the string


> Print every character available in this String object with
that character index position

You might also like