package hyq;
public class Arithmetric1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=10;
int b=6;
int s=0;
s=a%b;
System.out.println("a%b="+s);
++a;
--b;
s=++a + --b;
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("s="+s);
}
}
package hyq;
public class Arithmetic2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("浮点数:");
double a1=0,b1=0,c1=0;
a1=5/6;
System.out.println("5/6="+a1);
b1=5.0/6.0;
System.out.println("5.0/6.0"+b1);
c1=5/6.0;
System.out.println("5/6.0"+c1);
System.out.println("整数型:");
int a2=0,b2=0,c2=0;
a2=5/6;
System.out.println("5/6="+a2);
b2=(int)5.0/(int)6.0;
System.out.println("5.0/6.0="+b2);
c2=(int)5/(int)6.0;
System.out.println("5/6.0="+c2);
}
}
package hyq;
public class Logic {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean a,x,y,z;
a=(5>6) ? 1:0;
x=!a;
y=a&x;
z=x^y;
System.out.println("a="+a);
System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("z="+z);
}
}
a=(5>6) ? 1:0; 这里报错,不知道怎么改。
package hyq;
public class Convert {
public static void main(String[] args) {
// TODO Auto-generated method stub
byte a=0;
short b=0;
int c=0;
long d=0;
float e=0F;
double f=0D;
String s="10";
a=Byte.parseByte(s);
b=Short.parseShort(s);
c=Integer.parseInt(s);
d=Long.parseLong(s);
e=Float.parseFloat(s);
f=Double.parseDouble(s);
int MyInt=1234;
String MyString=""+MyInt;
}
}
package hyq;
import java.util.*;
public class InputNum {
public static void main(String[] args) {
// TODO Auto-generated method stub
float a=0;
float b=0F;
double c=0D;
String s="";
Scanner reader=new Scanner(System.in);
System.out.print("从键盘输入一串字符:");
s=reader.nextLine();
System.out.println("你输入的字符串是"+s);
System.out.print("从键盘输入一个整数:");
a=reader.nextInt();
System.out.println("你输入的整数是是"+a);
System.out.print("从键盘输入一个单精度浮点数:");
b=reader.nextFloat();
System.out.println("你输入的单精度浮点:");
System.out.print("从键盘输入一个双精度浮点数:");
c=reader.nextDouble();
System.out.println("你输入的双精度浮点数是"+c);
}
}