Microsoft
Software
Hardware
Network
Question : Java Programing
public class ReadBackwards
{
public static void main (String[]args)
{
String thisLine;
String[]fullText = new String[3];
int counter = 0;
String fileName = "backwards.java";
/**
* This will collect your input in a StringBuffer
* until you type "quit"
*/
StringBuffer sb = new StringBuffer();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.i
n));
String str = "";
do {
sb.append(str);
System.out.println("Input was: " + str + " length:" + str.length());
System.out.println(">promp
t ");
str = in.readLine();
}while(! str.equals("quit"));
} catch(IOException e) {System.out.println(e.getM
essage());
}
System.out.println("All input: " + sb.toString());
saveIt(fileName, sb.toString());
String s = readIt(fileName);
System.out.println("From file: " + s);
s = reverseIt(s);
System.out.println("From reverse: " + s);
System.out.println("End of program.");
}
public static void saveIt(String fileName, String s) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
out.write(s);
out.close();
} catch(IOException ex) {ex.printStackTrace(); }
}
public static String readIt(String fileName){
StringBuffer sb = new StringBuffer();
try {
String str;
BufferedReader in = new BufferedReader(new FileReader(fileName));
while((str = in.readLine()) != null)
sb.append(str);
} catch(IOException ex) {System.out.println(ex.get
Message())
; }
return(sb.toString());
}
public static String reverseIt(String s) {
StringBuffer sb = new StringBuffer();
for(int i = s.length()-1; i >= 0; i--) {
sb.append(s.charAt(i));
}
return(sb.toString());
}
}
Can someone Help, see the errors...
C:\prg421>javac ReadBackwards.java
ReadBackwards.java:18: cannot find symbol
symbol : class BufferedReader
location: class ReadBackwards
BufferedReader in = new BufferedReader(new InputStreamReader(Syst
em.in));
^
ReadBackwards.java:18: cannot find symbol
symbol : class BufferedReader
location: class ReadBackwards
BufferedReader in = new BufferedReader(new InputStreamReader(Syst
em.in));
^
ReadBackwards.java:18: cannot find symbol
symbol : class InputStreamReader
location: class ReadBackwards
BufferedReader in = new BufferedReader(new InputStreamReader(Syst
em.in));
^
ReadBackwards.java:28: cannot find symbol
symbol : class IOException
location: class ReadBackwards
} catch(IOException e) {System.out.println(e.getM
essage());
}
^
ReadBackwards.java:41: cannot find symbol
symbol : class BufferedWriter
location: class ReadBackwards
BufferedWriter out = new BufferedWriter(new FileWriter(fileName)
);
^
ReadBackwards.java:41: cannot find symbol
symbol : class BufferedWriter
location: class ReadBackwards
BufferedWriter out = new BufferedWriter(new FileWriter(fileName)
);
^
ReadBackwards.java:41: cannot find symbol
symbol : class FileWriter
location: class ReadBackwards
BufferedWriter out = new BufferedWriter(new FileWriter(fileName)
);
^
ReadBackwards.java:44: cannot find symbol
symbol : class IOException
location: class ReadBackwards
} catch(IOException ex) {ex.printStackTrace(); }
^
ReadBackwards.java:51: cannot find symbol
symbol : class BufferedReader
location: class ReadBackwards
BufferedReader in = new BufferedReader(new FileReader(fileName
));
^
ReadBackwards.java:51: cannot find symbol
symbol : class BufferedReader
location: class ReadBackwards
BufferedReader in = new BufferedReader(new FileReader(fileName
));
^
ReadBackwards.java:51: cannot find symbol
symbol : class FileReader
location: class ReadBackwards
BufferedReader in = new BufferedReader(new FileReader(fileName
));
^
ReadBackwards.java:55: cannot find symbol
symbol : class IOException
location: class ReadBackwards
} catch(IOException ex) {System.out.println(ex.get
Message())
; }
^
12 errors
C:\prg421>
Answer : Java Programing
You miss your imports
You need:
import java.io. BufferedReader;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.InputStreamReader;
at the top of your class
Random Solutions
E-mail's stuck (frozen) in the Local Delivery Queue - Exchange 2003 SP2 Enterprise
E-Machines EL1200 BSOD at Startup - Windows XP SP2
Exception in thread "main" org.hibernate.PropertyAcce
ssExceptio
n: IllegalArgumentException occurred while calling setter of com.web.dcr.DCRIncidentId.
dcrRef
Factory default settings for a PIX 506 and 506E
Windows 7 cached credentials-Account lockout
Word Document Import greyed out
Blue Screen shortly after Vista loads
Selecting second or third record on a sub form
window 2000 program menu
Trying to add Zend View Helper but get error Plugin by name not found in registry