원인 : 다수의 JAVA 버전이 설치 되어 있어서!!!
해결
1. 윈도우 키 + R - "regedit" 실행
2. HKEY_LOCAL_MACHINE - SOFTWARE - JavaSoft - Java Runtime Environment
3. CurrentValue 사용할 자바 버전으로 값 수정
다시 version을 보면
int []arr = {1,2,3,4,5};
for(int e : arr){
System.out.println(e);
}
|
public class Number {
public int num;
public Number(int n){
this.num = n;
}
public int getNum(){
return num;
}
}
class ExMain{
public static void main(String []args){
Number []arr = new Number[3];
arr[0] = new Number(1);
arr[1] = new Number(2);
arr[2] = new Number(3);
System.out.println("참조하는 인스턴스의 변수를 1증가후 출력");
for(Number e : arr)
e.num++;
for(Number e : arr)
System.out.print(e.getNum() + " ");
System.out.println("\n배열의 요소 변경 후 출력");
for(Number e : arr){
e = new Number(11);
e.num++;
System.out.print(e.getNum() + " ");
}
System.out.println("\n참조 값의 인스턴스 변수 재 출력");
for(Number e : arr)
System.out.print(e.getNum() + " ");
}
}
|
int []arr = new int[3]; arr[0] = 11; arr[1] = 22; arr[2] = 33; |
int []arr = new int[2] {1,2}; |
int []arr = new int[] {1,2}; |
int []arr = {1,2}; |
String []arr = new String[]; arr[0] = "Apple"; arr[1] = "Banana"; arr[2] = "Grape"; |
int [][]arr = new int [2][2]; // 2행 2열 배열 선언 |
int [][]arr = new int [2][2]; arr[0][0] = 1; arr[0][1] = 2; arr[1][0] = 3; arr[1][1] = 4; |
int [][]arr = new int[][] {{1,2},{3,4}}; |
int [][]arr = {{1,2},{3,4}}; |
int [][]arr = {{1},{2,3},{4,5,6}}; |
import java.util.Scanner;
class ExScanner
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
System.out.println("a: " + a);
String b = sc.nextLine();
System.out.println("b: " + b);
}
}
|
import java.util.Scanner;
class ExScanner
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
System.out.println("a: " + a);
sc.nextLine(); //공백을 읽어준다.
String b = sc.nextLine();
System.out.println("b: " + b);
}
}
|
class ExOutput
{
public static void main(String[] args)
{
System.out.print("print 메소드 실행");
System.out.print("\n개행 처리를 따로 해주어야 함\n");
System.out.println("println 메소드 실행");
int a = 1;
double b = 2.2;
String c = "this is string";
System.out.printf("a: %d, b: %f, c: %s", a,b,c);
}
}
|
class ExEscapeSe
{
public static void main(String[] args)
{
System.out.println("\n : 개행");
System.out.println("\t : 탭");
System.out.println("\" : 큰 따옴표");
System.out.println("\\ : 역 슬래쉬");
}
}
|
String str = "Hello" + '!';
|
String str = "Hello".concat(String.valueOf('!'));
|
String str = 11 + "Hello" + 22;
|
String str = new StringBuilder().append(11).append("Hello").append(22).toString();
|
String str = "Hello";
|
String str1 = "Hello";
String str2 = "Hello";
|
String str = "Hello";
System.out.println(str.length()); //5출력
|
String str1 = "Hello";
String str2 = "World!";
System.out.println(str1.concat(str2)); //HelloWorld! 출력
|
String str1 = "Hello";
String str2 = "World!";
System.out.println(str1.compareTo(str2)); //-15 출력
|
String str1 = "Hello";
String str2 = "Hello";
String str3 = new String(str1);
if(str1==str2)
System.out.println("같다");
else
System.out.println("다르다");
if(str1==str3)
System.out.println("같다");
else
System.out.println("다르다");
|