4번예시
package PACK01;
import java.util.Random;
public class HELLO {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
int rn = (new Random().nextInt(100));
int q = rn/10;//몫을 구한다
int r = rn%10;//나머지를 구한다.
int a = q+r;
System.out.println(rn+" "+q+" + "+r+" = "+a);
}
}
}
5번답
package PACK01;
public class HELLO {
public static void main(String[] args) {
byte a = 10;
short b = 20;
char c = 'T';
int d = 30;
long e = 40;
float g = 3.14f;//실수 4
double h = 3.14;//float보다 크다 8 double은 f안붙여도됨
boolean k = true;//값은 true,false만 사용가능
}
}
nextInt(n) =n-1까지의 숫자 나타낼수있음
char ch = 65;
char ch = 'A';
아스키 코드
System.out.println((int)ch);//강제형변환
System.out.println((char)('A'+i));
System.out.println((char)(num));
int A = 65;//'A'나 65나 ch나 같게 나온다
System.out.println((char)A);
package PACK01;
public class HELLO {
public static void main(String[] args) {
int A = 65;
char ch = 'A';
for (int i = 0; i < 26; i++) {
System.out.println((char)(65+i));
//System.out.println((char)A+i);
//System.out.println((char)ch+i);
}
}
}
7번 예시
package PACK01;
import java.util.Random;
import java.util.Scanner;
public class HELLO {
public static void main(String[] args) {
System.out.println("호랑이");
int input = (new Scanner(System.in).nextInt());
System.out.println("코끼리"+input);
}
}
package PACK01;
import java.util.Random;
import java.util.Scanner;
public class HELLO {
public static void main(String[] args) {
int input = (new Scanner(System.in).nextInt());
System.out.println(input);
}
}
package PACK01;
import java.util.Random;
import java.util.Scanner;
public class HELLO {
public static void main(String[] args) {
System.out.println("숫자를 입력하세요");
int input = (new Scanner(System.in).nextInt());
for (int i = 0; i < 10; i++) {
System.out.println(input+"*"+i+"="+(input*i));
}
}
}
8번
System.out.println("아스키코드를 입력하세요 0~127");
int input = (new Scanner(System.in).nextInt());
System.out.println((char)input);
shift enter 상관없이 ㄴ
9번
package PACK01;
public class HELLO {
public static void main(String[] args) {
int a = 30,b = 50, t;
t = a;//t=30 a=30 b=50
System.out.println(a+" "+b+" "+t);
a = b;//a=50 b=50 t=30
b = t;//b=30 a=50 t=30
System.out.println(a+" "+b+" "+t);
}
}
abc
한칸씩 미뤄넣기
package PACK01;
public class HELLO {
public static void main(String[] args) {
int a = 30,b = 50, c= 15, t ;
System.out.println(a+" "+b+" "+c);
t=a;
a=b;
b=c;
c=t;
System.out.println(a+" "+b+" "+c);
}
}
댓글