there are some errors in my code i have to print every 5th character in this sen
ID: 3533746 • Letter: T
Question
there are some errors in my code i have to print every 5th character in this sentence..
January is the first month and december is the last. Violet is a purple color as are lilac and plum.
this is my code:
import java.util.StringTokenizer;
import java.io.*;
import java.util.Scanner;
public class SecretDemo
{
public static void main(String[] args) throws IOException
{
//open a file
File file = new File("secret.txt");
Scanner inputFile = new Scanner(file);
String fileName;
String strToken;
int count = 0;
char letter;
StringBuilder strb = new StringBuilder();
fileName = inputFile.nextLine();
StringTokenizer strtkn = new StringTokenizer(fileName);
while(strtkn.hasMoreTokens())
{
strToken = strtkn.nextToken();
if(count%5 == 0)
{
letter = strToken.charAt(1);
System.out.println(Character.toUpperCase(letter));
}
count++;
}
System.out.println(strb);
}
}
output is: ANIS IT SHOULD BE JAVA!
Explanation / Answer
import java.util.StringTokenizer; import java.io.*; import java.util.Scanner; public class SecretDemo { public static void main(String[] args) throws IOException { //open a file FileInputStream fileIn =new FileInputStream("C:/Users/timacs/Desktop/eclipse_workspace/Sample/secret.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fileIn)); String strLine; String fileName; String strToken; int count = 0; char letter; String input="",line; StringBuilder strb = new StringBuilder(); while( ( line = br.readLine() ) != null) { input += line; } br.close(); System.out.println("sdfsaf"); for(int i=0,j=0;i
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.