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줄
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2669917 | if문 3단법이라고 하던가요? 이거 잘못되었나요? | 딸기우유 | 2024-09-28 |
2669835 | 정말정말 급합니다.... | 풀큰 | 2024-09-27 |
2669786 | 문자가 하나밖에 안나올까요 .... | 먹딸기 | 2024-09-27 |
2669738 | 자바초보 질문드려요 (__) pack()에 대해.. | 꽃짱구 | 2024-09-26 |
2669718 | 실무면접은 어떻게 보는지.. 실무자들이 중점적으로 보는건 어떤건지 궁금해요^^ (2) | 큐티베이비 | 2024-09-26 |
2669688 | 혹시 이거 해결할수 있으신 분 계신가요?? (1) | 그대와나 | 2024-09-26 |
2669656 | 비주얼 스튜디오 6.0 설치 문제 !!.. ^^ (1) | 핫체리 | 2024-09-25 |
2669602 | *this (3) | 돌삥 | 2024-09-25 |
2669548 | 한국형 주소검색이 되나요? (1) | 이거이름임 | 2024-09-25 |
2669524 | 썸네일 질문! (3) | agine | 2024-09-24 |
2669446 | 테마 설치중 처음보는 오류입니다 ㅠ | 라 | 2024-09-24 |
2669391 | 비트맵 이미지 변형시킬 때 깨지는 현상 (5) | 한샘가온 | 2024-09-23 |
2669334 | jquery 스터디 인원 모집.[모집완료] (10) | 화이트캣 | 2024-09-23 |
2669258 | 워드프레스에 프레지를 올리려면 어떻게 해야하나요? | 아라 | 2024-09-22 |
2669182 | [질문]파티클관련해서 소스좀 구할수없을까여? (4) | 나슬 | 2024-09-21 |
2669129 | meta 태그질문요 ㅠㅠ (4) | 엄지 | 2024-09-21 |
2669072 | 이 사이트에 쓰인 기능들이 궁금합니다. (6) | 댓걸 | 2024-09-20 |
2668996 | 음수값 주기 질문드려요!! (5) | 설화 | 2024-09-20 |
2668944 | 이 사이트의 테마는 뭘까요? | 갅지돋는슬아 | 2024-09-19 |
2668918 | InputStream 을 String형으로 변환 (7) | 은G | 2024-09-19 |