IF문으로 4개의 숫자를 입력받아 증가하는 순서대로 나열되는 자바 프로그래밍인데...2번 실행되는 문제가 발생했습니다.
달빛
import java.util.Scanner;
public class Sort
{
public static void main (String[] args)
{
System.out.println(Write a Four Nonnegative Integers. - Made By KDH);
System.out.println(************************************************);
// declare four variables: a,b,c,d. (After the swapping process, a will be the smallest number while d is the largest number, c the second largest, and so on.)
int a,b,c,d;
// create Scanner object keyboard.
Scanner keyboard = new Scanner(System.in);
// display a message that ask a user to input four numbers
// get user input values from keyboard and assign them into a,b,c, d one by one.
System.out.print(Insert First Number :);
a = keyboard.nextInt();
System.out.print(Insert Second Number :);
b = keyboard.nextInt();
System.out.print(Insert Third Number :);
c = keyboard.nextInt();
System.out.print(Insert Fourth Number :);
d = keyboard.nextInt();
System.out.println(*************************************************);
System.out.println(The Result Is);
//the case of all same
if((a==b) && (a==c) && (a==d))
{
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
// find the largest number by doing
// first, the smallest case in a
{
if((ab) && (ac) && (ad))
//and next is same with when we did in Lab Class(Three integers)
if(b==c)
if(cd)
{
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
if(bc)
if(cd)
{
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
if(dc)
if(bd)
{
System.out.println(a);
System.out.println(b);
System.out.println(d);
System.out.println(c);
}
if(c==d)
if(db)
{
System.out.println(a);
System.out.println(c);
System.out.println(d);
System.out.println(b);
}
if(cd)
if(db)
{
System.out.println(a);
System.out.println(c);
System.out.println(d);
System.out.println(b);
}
if(bd)
if(cb)
{
System.out.println(a);
System.out.println(c);
System.out.println(b);
System.out.println(d);
}
if(b==d)
if(dc)
{
System.out.println(a);
System.out.println(b);
System.out.println(d);
System.out.println(c);
}
if(db)
if(bc)
{
System.out.println(a);
System.out.println(d);
System.out.println(b);
System.out.println(c);
}
if(dc)
p; if(cb)
{
System.out.println(a);
System.out.println(d);
System.out.println(c);
System.out.println(b);
}
}
//second, the smallest case in b
//and do it like upper case
if((ba) && (bc) && (bd))
if(a==c)
if(cd)
{
System.out.println(b);
System.out.println(a);
System.out.println(c);
System.out.println(d);
}
if(ac)
if(cd)
{
System.out.println(b);
System.out.println(a);
System.out.println(c);
System.out.println(d);
}
if(dc)
if(ad)
{
System.out.println(b);
System.out.println(a);
System.out.println(d);
System.out.println(c);
}
if(c==d)
if(da)
{
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(a);
}
if(cd)
if(da)
{
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(a);
}
if(ad)
if(ca)
{
System.out.println(b);
System.out.println(c);
System.out.println(a);
System.out.println(d);
}
if(a==d)
if(dc)
{
System.out.println(b);
System.out.println(d);
System.out.println(a);
System.out.println(c);
}
if(da)
if(ac)
{
System.out.println(b);
System.out.println(d);
System.out.println(a);
System.out.println(c);
}
if(ca)
if(dc)
{
System.out.println(b);
System.out.println(d);
System.out.println(c);
System.out.println(a);
}
}
} // end main
// end class Sort
지금 문제가 되는게
이 빨간색 부분이 없을 때에는 정상적으로 실행(즉 한개의 케이스만 나타납니다)
되던게 빨간색부분을 넣고 하니
실행이 2번 되어버립니다
즉.
만약
31
1
32
33
이런식으로 숫자를 넣게 되면31
1
32
33
1
31
32
33
이런식으로 값이 출력되어버리는데...
뭐가 잘못된건가요??
되게 기초적인 문제같은데...ㅠㅠ
-
여우비 2023-07-19
예 맞아요 ^^
-
핑크펄 2023-07-19
그러니까 검정 부분까지는 4개가 출력되는데
빨간 부분을 넣으니까 8개가 출력된다는 말인가요?
검정 4줄 + 빨강 4줄 = 8줄