Click here to Skip to main content
15,885,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I saw lots of java problem and I'm a beginner , must of the problem required a test cases so the user can input how many test case he wants to test and then he will input how many line to the first test case , and so on

here is one of the problem I saw

Input

The first line contains the number of test cases T. T test cases follow:
The first line of each test case contains a number N. The next line contains N integers, denoting the predicted price of WOT shares for the next N days.
Output
Output T lines, containing the maximum profit which can be obtained for the corresponding test case.
Constraints
1 <= T <= 10
1 <= N <= 50000
All share prices are between 1 and 100000
Sample Input
3
3
5 3 2
3
1 2 100
4
1 3 1 2
Sample Output
0
197
3


but the problem I work on ask me to

first ask the user to enter the minimum size of picture
then he enter how many pic he has, the number of picture will be the number of lines , each line had hight and width.
if the H and W is greater than the minimum size he would print crop it and it it's smaller he would print another and if it's just equal to the minimum size he would print accepted,,, so for each line there would be an output , I just receive one out put for the last input I wrote

sample input would be :
180
3
640 640
120 300
180 180

sample output :
CROPIT
ANOTHER
ACCEPTED


Thank you

What I have tried:

Java
import java.util.*;


public class photo {
	
	public static void main(String[] args){
		
		Scanner input = new Scanner (System.in);
		//the minimum size of the picture must be (MxM)
		int M = input.nextInt();
		//number of pic
		int K = input.nextInt();
		 int y=0;
		 int x=0 ; 
			  
		 for (int i = 0; i <K; i++) {
			 
			  x=Integer.parseInt(input.next());
			  y=Integer.parseInt(input.next()); 
		 } 
		 
		 	 
		 
		 if (x>M & y>M)
		 
			System.out.println("CROPIT"); 	 
		 
		 else
			 if(x<M & y<M)
			 System.out.println("ANOTHER");  
			 	 
		 
		 else 
			 System.out.println("ACCEPTED"); 
		 }
		 }
Posted
Updated 17-Sep-18 15:47pm
v6
Comments
Patrice T 17-Sep-18 12:19pm    
Show you code !
Patrice T 17-Sep-18 14:00pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
wseng 17-Sep-18 12:45pm    
Post the code you have tried.

1 solution

Quote:
I just receive one output for the last input I wrote...
Because if-condition is placed outside for-loop.
I would suggest you to use ArrayList in this case.
public class photo {                                               
                                                                   
    public static void main(String[] args) {                       
                                                                   
        ArrayList list = new ArrayList<>();                        
                                                                   
        Scanner input = new Scanner(System.in);                    
        //the minimum size of the picture must be (MxM)            
        int M = input.nextInt();                                   
        //number of pic                                            
        int K = input.nextInt();                                   
        int y = 0;                                                 
        int x = 0;                                                 
                                                                   
                                                                   
        for (int i = 0; i < K; i++) {                              
                                                                   
            x = Integer.parseInt(input.next());                    
            y = Integer.parseInt(input.next());                    
                                                                   
            if (x > M & y > M)                                     
                list.add("CROPIT");                                
//            System.out.println("CROPIT");                        
                                                                   
            else if (x < M & y < M)                                
                list.add("ANOTHER");                               
//            System.out.println("ANOTHER");                       
                                                                   
            else                                                   
                list.add("ACCEPTED");                              
//            System.out.println("ACCEPTED");                      
                                                                   
        }                                                          
                                                                   
        for (Object a : list) {                                    
            System.out.println(a);   // print list                 
        }                                                          
    }                                                              
}                                                                  
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900