- File f = new File("MyData.txt");
- Scanner in = new Scanner(f);
- PrintWriter out = new PrintWriter(f);
double sum = 0.0;
while (in.hasNextDouble()) {
double n = in.nextDouble();
sum += n;
}
- OK
- OK
- Error
- OK
try {
PrintWriter out = new PrintWriter(new File("MyOutput.txt"));
out.println("This is my output file.");
out.close();
} catch (FileNotFoundException fnf) {
System.err.println("Could not open file.");
}
public class Thingy implements Comparable<Thingy>
{
private int value;
public Thingy(int v)
{
value = v;
}
public int getValue()
{
return value;
}
public int compareTo(Thingy that) {
return this.value - that.value;
}
}
public static void cheer(int n)
{
if (n < 0)
{
throw new IllegalArgumentException
System.err.println("No negatives allowed");
System.exit(1);
}
for (int i = 1; i <= n; i++)
{
System.out.println("Hip-");
}
System.out.println("Hooray!");
}
public interface Usable {
public void showValues();
public boolean hasZeroValue();
public int getZeroLocation();
public double solve(int zero);
}
-
d)
c)
b)
a)
- d) public void method() throws MyException
- e) (all of the above)
- j) if (m instanceof Circle)
- a) File