import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
File file = new File(args[0]);
BufferedReader in = new BufferedReader(new FileReader(file));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
boolean upperCase=true;
for(int i=0;i<line.length();i++){
char c=line.charAt(i);
if(c>='a' &&c<='z'){
if(upperCase){
sb.append((char)(c-32));
}else{
sb.append(c);
}
upperCase=!upperCase;
}else if(c>='A'&&c<='Z'){
if(!upperCase){
sb.append((char)(c+32));
}else{
sb.append(c);
}
upperCase=!upperCase;
}else{
sb.append(c);
}
}
sb.append('\n');
}
System.out.print(sb);
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
File file = new File(args[0]);
BufferedReader in = new BufferedReader(new FileReader(file));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
boolean upperCase=true;
for(int i=0;i<line.length();i++){
char c=line.charAt(i);
if(c>='a' &&c<='z'){
if(upperCase){
sb.append((char)(c-32));
}else{
sb.append(c);
}
upperCase=!upperCase;
}else if(c>='A'&&c<='Z'){
if(!upperCase){
sb.append((char)(c+32));
}else{
sb.append(c);
}
upperCase=!upperCase;
}else{
sb.append(c);
}
}
sb.append('\n');
}
System.out.print(sb);
}
}
No comments:
Post a Comment