Write a program to input a string and then display it in Upper Case and also print the frequency of any character from the string. import java.io.*; import java.util.*; class StrCount
{
public static void main(String args[])throws IOException
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a string:");
String n=in.nextLine();
String n1=n.toUpperCase();
System.out.println("The string in upper case:");
System.out.println(n1);
char ch='T'; int k=0;
System.out.println("Charachter to be searched for is T."); for(int i=0;i=1)
System.out.print("Character "+ch+" occurs "+k+" times.");
else
System.out.println("Character doesn't occur in this String..");
}
}
Output:
Enter a string:
Aman Himanshu …show more content…
Sumit Kavish Bhagyashree Dipti Teena Meghna
The string in upper case:
AMAN HIMANSHU SUMIT KAVISH BHAGYASHREE DIPTI TEENA MEGHNA
Charachter to be searched for is E
Character E occurs 5 times.
Program 2:
Write a program to read the name of 5 students through keyboard and store them in a file “name.txt”.
import java.io.*; class WriteFile
{
public static void main(String args[])throws …show more content…
IOException
{
String fileName=("name.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
FileWriter fw=new FileWriter(fileName);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter outFile=new PrintWriter(bw); for(int i=0;i0) scan=null; scan=new File("hh.txt"); Scanner in =null; try { in=new Scanner(scan); // System.out.println(scan); } catch(FileNotFoundException e) { System.out.println("File not found..!!"); System.exit(0); }
while(true) { String tt=in.next(); System.out.println(tt); if(in.hasNextBoolean()) break; } }
}
Output:
Hiii...We
are the TWELTHIES...
SUPER
SENIORS....
Program 8:
Write a program to input a string and separate words in it using String Tokenizer class. import java.io.*; import java.util.*;
class CountSpace { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i=0; System.out.println("Input a String:"); StringTokenizer st=new StringTokenizer(br.readLine()); i=st.countTokens(); for(int
j=0;j