我在java中编写测试用例时遇到问题 [英] I have a problem with coding test cases in java

查看:91
本文介绍了我在java中编写测试用例时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我看到很多java问题而且我是初学者,必须要问一个测试用例的问题所以用户可以输入多少测试用例他想测试然后他会输入多少行到第一个测试用例,依此类推



这里是我看到的问题之一



输入



第一行包含测试用例T的数量。 T测试用例如下:

每个测试用例的第一行包含一个数字N. 下一行包含N个整数,表示WOT份额的预测价格接下来的N天。

输出

输出T行,包含相应测试用例可获得的最大利润。

约束

1< = T< = 10

1< = N< = 50000

所有股价介于1和100000之间

样品输入

3

3

5 3 2

3
1 2 100

4

1 3 1 2

样品输出

0

197

3





但我工作的问题要求我



首先要求用户输入最小尺寸的图片

然后他输入他有多少张图片,图片的数量将是行数,每行都有高度和宽度。

如果H和W大于他打印裁剪的最小尺寸,它会更小,他会打印另一个,如果它只是等于他打印接受的最小尺寸,那么对于每一行都会作为输出,我只收到一个输出我写的最后一个输入



样本输入将是:

180

3

640 640

120 300

180 180



样本输出:

CROPIT

另一个

接受





谢谢



我的尝试:



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:

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"); 
		 }
		 }

推荐答案

引用:

我只收到一个输出,用于我写的最后一个输入...

I just receive one output for the last input I wrote...

因为if-condition被置于for循环之外。

我建议你在这种情况下使用 ArrayList

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                 
        }                                                          
    }                                                              
}                                                                  


这篇关于我在java中编写测试用例时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆