- Dec 6, 2001
- 2,171
- 1
- 0
Here's my coding:
public class UsingForMod {
//Written by Chris Cramer
//Assignment 4 Part IIa
//This is a program that prints multiples of a particular number
//with input from the keyboard
public static void main(String arg[]){
int baseNumber=getNumber("base number");
int multiplier=getNumber("multiplier");
doMultiplesOf(baseNumber,multiplier);
}//end main
public static void doMultiplesOf(int n, int m) {
for (int x=0; x<=m; x++)
{
display("The number "+n+" multiplied by "+x+" is "+x*n);
}//close for
}//close doMultiplesOf
public static int getNumber(String n){
int number=0;
display("Please enter the "+n);
try {
String integerString=keyboard.readLine();
number=Integer.parseInt(integerString);
}//close try
catch(Exception e){
display("You need to enter an integer");
exitProgram();
}//close catch
return number;
}//close getNumber
public static void exitProgram(){
display("Exiting the program");
System.exit(0);
}
public static void display(String n){
System.out.println(n);
}//close display
}//close UsingFor
I get an error saying that this:
> javac UsingForMod.java
UsingForMod.java:25: Undefined variable or class name: keyboard
String integerString=keyboard.readLine();
Do i have to add a new BufferReader in there to take the term to make it a defined varaible or a throws? what do i need to do? Thanks everyone!
-Chris
public class UsingForMod {
//Written by Chris Cramer
//Assignment 4 Part IIa
//This is a program that prints multiples of a particular number
//with input from the keyboard
public static void main(String arg[]){
int baseNumber=getNumber("base number");
int multiplier=getNumber("multiplier");
doMultiplesOf(baseNumber,multiplier);
}//end main
public static void doMultiplesOf(int n, int m) {
for (int x=0; x<=m; x++)
{
display("The number "+n+" multiplied by "+x+" is "+x*n);
}//close for
}//close doMultiplesOf
public static int getNumber(String n){
int number=0;
display("Please enter the "+n);
try {
String integerString=keyboard.readLine();
number=Integer.parseInt(integerString);
}//close try
catch(Exception e){
display("You need to enter an integer");
exitProgram();
}//close catch
return number;
}//close getNumber
public static void exitProgram(){
display("Exiting the program");
System.exit(0);
}
public static void display(String n){
System.out.println(n);
}//close display
}//close UsingFor
I get an error saying that this:
> javac UsingForMod.java
UsingForMod.java:25: Undefined variable or class name: keyboard
String integerString=keyboard.readLine();
Do i have to add a new BufferReader in there to take the term to make it a defined varaible or a throws? what do i need to do? Thanks everyone!
-Chris
