Exam01
class A{}
public class Exam01 {
public static int sum(int n,int m) {
return n + m;
}//메소드
public static void main(String[] ar) {
int i;
int s;
char a;
i=10;// int는 정수타입인데 실수가나와서 오류됨
int n=19;
int m=015;//8진법..5*8^0+1*8^1=13
int k=0x15;//16진법..5*16^0+1*16^1=21
int b=0b0101;//1*2^0+0*2^1+1*2^2+0*2^3=5
byte c=127;//-128~+127
long g=24L;
double e=1234E-4;//=1234/10000
float aa=0.1234f;//f를 붙여줘야함
double bb=.1234D;//D가 없어도 괜찮다.
char cc='\u0041';
final double pi = 3.141592;
String toolName="jdk";
s=sum(i,10);
a='?';
System.out.println(a);//?
System.out.println("Hello");//Hello
System.out.println("sum="+s);
}
}
Exam02
public class Exam02 {
public static void main(String[] ar) {
byte b=127;
int i=100;
System.out.println(b+i);
System.out.println(10/4);
System.out.println(10.0/4);
System.out.println((char)0x12340041);
System.out.println((byte)(b+i));
System.out.println((int)2.9+1.8);//2+1.8-->3.8
System.out.println((int)(2.9+1.8));//4.7-->4
System.out.println((int)2.9+(int)1.8);//2+1--->3
}
}
Exam03
import java.io.*;
public class Exam03 {
public static void main(String[] ar) throws IOException {
System.out.print("키보드 하나를 누르시오");
char a=(char)System.in.read();
System.in.read();
System.in.read();
System.out.println("a="+a);
System.out.print("숫자하나를 누르세요.");
int b=System.in.read()-48;//int b=System.in.read()-'0';
System.out.println("b="+b);
}
}
Exam04
import java.util.Scanner;
public class Exam04 {
public static void main(String[] ar) {
Scanner scan=new Scanner(System.in);
System.out.println("이름을 입력하세요?");
String name=scan.next();
System.out.println("name="+name);
System.out.println("나이를 집어넣으시오?");
int age=scan.nextInt();
System.out.println("name="+name+"\n"+"age="+age);
scan.close();
}
}