C
Cross Tops
Unregistered / Unconfirmed
GUEST, unregistred user!
谁能帮5把这个程序简化一下,要求用int myArray[]=new int[y]语句,谢了。急急急~~~~~
class NewMathtable{
public static void main(String[]args)
{
int x,y;
char z;
x=gettable();
y=getline();
z=getoperator();
int result;
Screen.message(" The table is :");
Screen.newline();
int myarray[]=new int[y];
for(int i=1;i<=myarray.length;i++)
{
Screen.writeint(x,2);
Screen.writechar(z,2);
Screen.writeint(i,2);
Screen.message(" = ");
Screen.writeint(claculate (x,i,z),2);
Screen.newline();
//}while(i>y);
}
}
public static int gettable()
{ //procedure1
int table;
do
{
Screen.message(" Enter Table: ");
table=Keyboard.readInt();
}while(table<1||table>12);
return table;
//return to x
}
public static int getline()
{ //procedure2
int line;
do
{
Screen.message(" Enter lines: ");
line=Keyboard.readInt();
}while(line<1||line>20);
return line;
//return to y
}
public static char getoperator()
{ //procedure3
char operator;
do
{
Screen.message(" Enter operator: ");
operator=Keyboard.readChar();
}while(operator!='*'&&operator!='/'&&operator!='+'&&operator!='-');//only *,/,+,-allowed
return operator;
//return to z
}
public static int claculate (int x,int y,char z)
{
int myarray[]=new int[y];
int result=0;
for(int i=1;i<=myarray.length;i++)
{
if(z=='*')
{
result=x*i;
}
if(z=='+')
{
result=x+i;
}
if(z=='/')
{
result=x/i;
}
if(z=='-')
{
result=x-i;
}
}
return result;
}
}
多谢~~多谢~~~呵呵~~~
class NewMathtable{
public static void main(String[]args)
{
int x,y;
char z;
x=gettable();
y=getline();
z=getoperator();
int result;
Screen.message(" The table is :");
Screen.newline();
int myarray[]=new int[y];
for(int i=1;i<=myarray.length;i++)
{
Screen.writeint(x,2);
Screen.writechar(z,2);
Screen.writeint(i,2);
Screen.message(" = ");
Screen.writeint(claculate (x,i,z),2);
Screen.newline();
//}while(i>y);
}
}
public static int gettable()
{ //procedure1
int table;
do
{
Screen.message(" Enter Table: ");
table=Keyboard.readInt();
}while(table<1||table>12);
return table;
//return to x
}
public static int getline()
{ //procedure2
int line;
do
{
Screen.message(" Enter lines: ");
line=Keyboard.readInt();
}while(line<1||line>20);
return line;
//return to y
}
public static char getoperator()
{ //procedure3
char operator;
do
{
Screen.message(" Enter operator: ");
operator=Keyboard.readChar();
}while(operator!='*'&&operator!='/'&&operator!='+'&&operator!='-');//only *,/,+,-allowed
return operator;
//return to z
}
public static int claculate (int x,int y,char z)
{
int myarray[]=new int[y];
int result=0;
for(int i=1;i<=myarray.length;i++)
{
if(z=='*')
{
result=x*i;
}
if(z=='+')
{
result=x+i;
}
if(z=='/')
{
result=x/i;
}
if(z=='-')
{
result=x-i;
}
}
return result;
}
}
多谢~~多谢~~~呵呵~~~