Find the Maximum Value July Lunchtime 2017

plz tell what is the error showing nzec in one test case

import java.util.ArrayList;

import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class codeforces {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	ArrayList<Integer> obj = new ArrayList<Integer>();
	scan.nextLine();
	while(n-->0) {
		String s = scan.nextLine();
		int count =0;
		for(int i=0;i<s.length();i++) {
			if(Character.isDigit(s.charAt(i))){
				obj.add(Integer.parseInt(Character.toString(s.charAt(i))));
				count++;
			}
		}
		//System.out.println(count);
		int num =count-1;
		obj.remove(obj.indexOf(num));
		//System.out.println("\n"+obj);
		System.out.println(Collections.max(obj));
		obj.clear();
	}
}

}

import java.util.ArrayList;
import java.util.Collection; import java.util.Collections; import java.util.Scanner;

public class codeforces {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
ArrayList obj = new ArrayList();
scan.nextLine();
while(nā€“>0) {
String s = scan.nextLine();
int count =0;
for(int i=0;i<s.length();i++) {
if(Character.isDigit(s.charAt(i))){
obj.add(Integer.parseInt(Character.toString(s.charAt(i))));
count++;
}
}
//System.out.println(count);
int num =count-1;
obj.remove(obj.indexOf(num));
//System.out.println(ā€œ\nā€+obj);
System.out.println(Collections.max(obj));
obj.clear();
}
}
}

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class codeforces {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	ArrayList<Integer> obj = new ArrayList<Integer>();
	scan.nextLine();
	while(n-->0) {
		String s = scan.nextLine();
		String s1[] = s.split("\\s");
		int count =0;
		for(int i=0;i<s1.length;i++) {
			obj.add(Integer.parseInt(s1[i]));
			count++;
		}
		int num =count-1;
		obj.remove(obj.indexOf(num));
		//System.out.println("\n"+obj);
		System.out.println(Collections.max(obj));
		obj.clear();
	}
}

}

Your code will only work if the array only has single digit integer.

2 Likes

i have submitted this code with long also but still the same nzec

What difference will long make?

2 Likes

Thanks i Understood :slight_smile: