2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter number (0 to quit): ");
//largest to-do
double largest = scan.nextDouble();
double count = 0;
while (largest != 0) {
double input = scan.nextDouble();
//max
if (input > largest) {
// not zero
// while (input > largest){
//
// }
largest = input;
//counter
count = 0;
}
//counter start
if(input==largest){
count++;
}
if (input == 0) {
System.out.println("Largest #: " + largest);
System.out.println("Occurance: " + count);
}
}
}
}
이 프로그램이 작동합니다! 그러나 그는 그 완전한 생각하지 ... 처럼 사용자는 출력입력을 만드는 방법 특정 번호를 읽지 마십시오
-17 -5 -2 -1 -1 -1 0
를 입력하려고하면 :
Max: 0
Occurrence: 1
비록 :
: 내 마음에 내가 원하는Max: -1
Occurrence: 3
어떻게 배열을 사용하지 않고이 작업을 수행 할 수 있습니까? 나는 카운터 위에 시작한 코드의 일부분을 알고 있습니다.
미리 감사드립니다.
그래서 0은 중지 지점을 의미합니까? 편지 나 다른 캐릭터를 멈추게할까요? – dimwittedanimal
0을 숫자로 유지하려면 'input! = 0 && input>가 0이기 때문에 0으로 읽혀 처리되기 때문에'입력> 최대 '에 추가로 체크해야합니다. – Al1
@ dimwittedanimal 나는이 과정에서 숫자를 생략 할 수있는 방법을보고 싶었지만 그럴 수 있었다. – hellothere