|
|
back to boardDiscussion of Problem 1068. SumCompilation error showing bad class hierarchy but wrking correctly in idle Posted by Paul 6 Nov 2012 17:47 package practice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Sum {
public static void main(String[] args) { // TODO Auto-generated method stub //Scanner sc = new Scanner (System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int x = 0; int sum = 0; try { x = (int)br.read(); System.out.println("x" +x); if(x >0){ for(int i =1; i <= x ;i++){ sum = sum +i; } } else { for(int i =x; i <=1 ;i++){ sum = sum +i; } }
} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
System.out.println(sum); } } |
|
|