Java:j' ai une erreur dans mon prg

Fermé
domxaline - 28 févr. 2012 à 14:26
irmeche Messages postés 71 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 18 juillet 2014 - 28 févr. 2012 à 15:00
Bonjour,
voilà j'écris ce prg mais j'ai 2 erreur dans la main,quelqu'un peut m'aider le corriger

import java.io.*;
public class StudentMarks 
{
	int r1=0,r2=0,r3=0,r4=0,rn=1;
	static BufferedReader br;
	
	public StudentMarks( int num)
	{ 
		int arr[]= new int [num];
		try 
		{ 
		 for(int i=0; i<arr.length;i++)
		 { 
			 System.out.println("enter the marks for roll nb"+rn);
			 arr[i]=Integer.parseInt(br.readLine());
			 rn++;
		 }
		 for(int j=0; j<arr.length;j++)
		 { 
			 if (arr[j]>=0&& arr[j]<=40)
			 {
				 r1++;
			 }
			 else if (arr[j]>40 && arr[j]<=60)
			 { 
				 r2++;
			 }
			 else if (arr[j]>60 && arr[j]<=80)
			 { 
				 r3++;
			 }
			 else if (arr[j]>80 && arr [j]<=100)
			 { 
				 r4++;
			 }
		 }
		 System.out.println("Students securing marks in the range of 0-40 are \t"+r1);
		 System.out.println("Students securing marks in the range of 40-60 are \t"+r2);
		 System.out.println("Students securing marks in the range of 60-80 are \t"+r3);
		 System.out.println("Students securing marks in the range of 80-100 are \t"+r4);
		}
		//end of try
		catch(Exception exp)
		{ 
			System.out.println(exp);
		}
		//end catch
	}
//end constructor
public static void main (String args[])
{ 
	int sm;
	
	try
	{ 
		br=new BufferedReader(new inputStreamReader(System.in));
		System.out.println("Enter the total nb of students in the class");
		int total_students=Integer.parseInt(br.readLine());
		StudentMarks.sm=new StudentMarks(total_students);
	}
	//end of try
	catch(Exception exp)
	{
		System.out.println(exp.getMessage());
	}//end of catch
}//end main
}//end of class
}


eclipse m'indique erreur dans la ligne
br=new BufferedReader(new inputStreamReader(System.in));


inputStreamReader cannot be resolved to a type
sm cannot be resolved or is not a field


aidez moi svp pour ce prg
A voir également:

1 réponse

irmeche Messages postés 71 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 18 juillet 2014 17
Modifié par irmeche le 28/02/2012 à 15:01
essaye comme ca :

import java.io.*;  

public class StudentMarks {  
 int r1 = 0, r2 = 0, r3 = 0, r4 = 0, rn = 1;  
 static BufferedReader br;  
 public StudentMarks(int num) {  
  int arr[] = new int[num];  
  try {  
   for (int i = 0; i < arr.length; i++) {  
    System.out.println("enter the marks for roll nb" + rn);  
    arr[i] = Integer.parseInt(br.readLine());  
    rn++;  
   }  
   for (int j = 0; j < arr.length; j++) {  
    if (arr[j] >= 0 && arr[j] <= 40) {  
     r1++;  
    } else if (arr[j] > 40 && arr[j] <= 60) {  
     r2++;  
    } else if (arr[j] > 60 && arr[j] <= 80) {  
     r3++;  
    } else if (arr[j] > 80 && arr[j] <= 100) {  
     r4++;  
    }  
   }  
   System.out.println("Students securing marks in the range of 0-40 are \t"+ r1);  
   System.out.println("Students securing marks in the range of 40-60 are \t"+ r2);  
   System.out.println("Students securing marks in the range of 60-80 are \t"+ r3);  
   System.out.println("Students securing marks in the range of 80-100 are \t"+ r4);  
  }  
  // end of try  
  catch (Exception exp) {  
   System.out.println(exp);  
  }  
  // end catch  
 }  

 // end constructor  
 public static void main(String args[]) {  
    
  try {  
   br = new BufferedReader(new InputStreamReader(System.in));  
   System.out.println("Enter the total nb of students in the class");  
   int total_students = Integer.parseInt(br.readLine());  
   StudentMarks sm = new StudentMarks(total_students);  
  }  
  // end of try  
  catch (Exception exp) {  
   System.out.println(exp.getMessage());  
  }// end of catch  
 }// end main  
}// end of class  



0