█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 4279

Problema 0x25 - Suma de un subarreglo

  • Autor: arturor72
  • Fecha: 2021-06-05 00:18:51 UTC (Hace 15 días)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#2
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#3
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#4
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#5
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#6
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#7
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#8
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#9
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#10
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#11
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#12
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#13
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
#14
Error de compilación
                      Main.java:2: error: class SubArreglo is public, should be declared in a file named SubArreglo.java
public class SubArreglo{                                                        
       ^
1 error

                    
Puntos totales: 0 / 100

Código

import java.util.Scanner;                                                       
public class SubArreglo{                                                        
                                                                                
    public static void main(String... args){                                    
        Scanner  sc=new  Scanner(System.in);                                    
        int n=sc.nextInt();                                                     
        int arr[]=new int[n];                                                   
        for(int i=0; i<n; i++){                                                 
            arr[i]=sc.nextInt();                                                
        }                                                                       
        int consulta=sc.nextInt();                                              
        for(int i=0; i<consulta; i++){                                          
            int p=sc.nextInt();                                                 
            int q=sc.nextInt();                                                 
            int c=0;                                                            
            for(int j=p; j<=q; j++) c+=arr[j];                                  
            System.out.println(c);                                              
        }                                                                       
        sc.close();                                                             
    }                                                                           
                                                                                
}