java古明源2024.9.27
EnumTest.java:
package gu;
public class EnumTest {
public static void main(String[] args) {
Size s=Size.SMALL;
Size t=Size.LARGE;
//s和t引用同一个对象?
System.out.println(s==t); //
//是原始数据类型吗?
System.out.println(s.getClass().isPrimitive());
//从字符串中转换
Size u=Size.valueOf("SMALL");
System.out.println(s==u); //true
//列出它的所有值
for(Size value:Size.values()){
System.out.println(value);
}
}
}
enum Size{SMALL,MEDIUM,LARGE};
TestDouble.java:
package gu;
public class TestDouble {
public static void main(String args[]) {
System.out.println("0.05 + 0.01 = " + (0.05 + 0.01));
System.out.println("1.0 - 0.42 = " + (1.0 - 0.42));
System.out.println("4.015 * 100 = " + (4.015 * 100));
System.out.println("123.3 / 100 = " + (123.3 / 100));
}
}
动手动脑:
package ming;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int X=100;
int Y=200;
System.out.println("X+Y="+X+Y);
System.out.println(X+Y+"=X+Y");
}
}
四则运算
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char* argv[])
{
int i,j,k,sum;
for(int t = 0;t<30;t++)
{
printf("第%d道题:",t+1);
i = rand()%50;
j = rand()%50;
k = rand()%4;
switch(k)
{
case 0:
sum = i+j;
printf("%d+%d=%d\n",i,j,sum);
break;
case 1:
sum = i-j;
printf("%d-%d=%d\n",i,j,sum);
break;
case 2:
sum = i*j;
printf("%d*%d=%d\n",i,j,sum);
break;
case 3:
sum = i/j;
printf("%d/%d=%d\n",i,j,sum);
break;
default:
printf("出错!\n");
break;
}
}
return 0;
}