hi. Is it possible to use bufferedreader in an applet? if so where am i going wrong here ?
im getting the following error: E:\CIS26\Hw1App .java:23: unreported exception java.io.IOExcep tion; must be caught or declared to be thrown. String s = keyboard.readLi ne ();
I tried writing "throws exception" after declaring paint, but then it compiles, but when it runs it gives the error: "Exception in thread "main" java.lang.NoSuc hMethodError: main
Press any key to continue . . ."
import java.io.Buffere dReader;
import java.io.*;
import javax.swing.JAp plet;
import java.awt.Graphi cs;
public class Hw1App extends JApplet{
public void init (){}
public static void paint () {
int n=0;
int positives=0;
int negatives=0;
int zeros=0;
int i=0;
System.out.prin tln("Please enter 7 numbers with one space in between");
System.out.prin tln("and the computer will output how many are positive, negative, and zeros.");
BufferedReader keyboard= new BufferedReader (new InputStreamRead er (System.in));
String s = keyboard.readLi ne ();
int k=s.length();
while (i<k-1){
int x=Integer.parse Int(s.substring (0,i+1));
if (x>0) //adds up the positive numbers that were input
positives++;
else if (x<0) //adds up the negative numbers that were input
negatives++;
else if (x==0) //adds up the zero numbers that were input
zeros++;
i++;
}
im getting the following error: E:\CIS26\Hw1App .java:23: unreported exception java.io.IOExcep tion; must be caught or declared to be thrown. String s = keyboard.readLi ne ();
I tried writing "throws exception" after declaring paint, but then it compiles, but when it runs it gives the error: "Exception in thread "main" java.lang.NoSuc hMethodError: main
Press any key to continue . . ."
import java.io.Buffere dReader;
import java.io.*;
import javax.swing.JAp plet;
import java.awt.Graphi cs;
public class Hw1App extends JApplet{
public void init (){}
public static void paint () {
int n=0;
int positives=0;
int negatives=0;
int zeros=0;
int i=0;
System.out.prin tln("Please enter 7 numbers with one space in between");
System.out.prin tln("and the computer will output how many are positive, negative, and zeros.");
BufferedReader keyboard= new BufferedReader (new InputStreamRead er (System.in));
String s = keyboard.readLi ne ();
int k=s.length();
while (i<k-1){
int x=Integer.parse Int(s.substring (0,i+1));
if (x>0) //adds up the positive numbers that were input
positives++;
else if (x<0) //adds up the negative numbers that were input
negatives++;
else if (x==0) //adds up the zero numbers that were input
zeros++;
i++;
}
Comment