Input output sample - 04

Input Specification:
The input data for any test case consists of a sequence of one or more non-negative integers. The last number in each sequence is -1, which signifies the end of data for that particular test case. The end of data for the entire input is the number -1 as the first value in a test case and it is not considered to be a separate test.

Output Specification:
For each test case produces a line of output, this line contains the maximum value in a test case.

Sample Input:
4
10
9
-1
5
4
-1
-1

Sample Output:
10
5


Pascal Code:
program sample04 (input,output);
var n,max_val: integer;
begin
    while not eof(input) do begin
        readln(n);
        if n=-1 then break;
        max_val:=n;
        while not eof(input) do begin
            readln(n);
            if n=-1 then break;
            if n>max_val then max_val:=n;
        end;
        writeln(max_val);
    end;
end.


C Code:
#include <stdio.h>

int main(){
    int n,max_val;
    while(scanf("%d",&n)==1 && n!=-1){
        max_val=n;
        while(scanf("%d",&n)==1 && n!=-1)
            if(n>max_val) max_val=n;
        printf("%d\n",max_val);
    }
    return 0;
}


C++ Code:
#include <iostream>

using namespace std;

int main(){
    int n,max_val;
    while(cin>>n && n!=-1){
        max_val=n;
        while(cin>>n && n!=-1)
            if(n>max_val) max_val=n;
        cout<<max_val<<endl;
    }
    return 0;
}


Java Code:
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n,max_val;
        while(sc.hasNext()){
            n=sc.nextInt();
            if(n==-1) break;
            max_val=n;
            while(sc.hasNext()){
                n = sc.nextInt();
                if(n==-1) break;
                if(n>max_val)max_val=n;
            }
            System.out.println(max_val);
        }
    }
}