第三章--数据类型、变量和表达式:
class ByteTest
{
public static void main ( String [] args )
{
int a;
byte b;
a=256;
b=(byte)a;
( b );
}
}
class FloatTest
{
public static void main ( String [] args )
{
float f;
f = ;
( f );
}
}
3.
import ;
public puteArea
{
public static void main(String[ ] args)
{
double radius;
double area;
radius = (("请输入半径值"));
area = radius * radius *;
(null,"area = "+ area);
}
}
第四章—控制:
1.
// : Contain the methods for reading int, double, and
// string values from the keyboard
import .*;
public class MyInput
{
// Read a string from the keyboard
public static String readString()
{
BufferedReader br
= new BufferedReader(new InputStreamReader(), 1);
// Declare and initialize the string
String string = " ";
// Get the string from the keyboard
try
{
string = ();
}
catch (IOException ex)
{
(ex);
}
// Return the string obtained from the keyboard
return string;
}
// Read an int value from the keyboard
public static int readInt()
{
return (readString());
}
// Read a double value from the keyboard
public static double readDouble()
{
return (readString());
}
// Read a byte value from the keyboard
public static double readByte()
{
return (readString());
}
// Read a short value from the keyboard
public static double readShort()
{
return (readString());
}
// Read a long value from the keyboard
public static double readLong()
{
return (readString());
}
// Read a float value from the keyboard
public static double readFloat()
{
return (readString());
}
}
2.
import .*;
public class pute
{
publi
java代码实例 来自淘豆网m.daumloan.com转载请标明出处.