我的问题出了问题。你们有人可以帮我解决这个问题吗? [英] I am having a trouble with my problem. Can anyone of you please help me sort this out?

查看:85
本文介绍了我的问题出了问题。你们有人可以帮我解决这个问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

您应该至少使用循环和条件。当一个数字被3整除时,立即打印出来。

注意:调用第一个函数时,可以使用提供的数组a1。

样本运行:

divThree({3,53,234,72,31,32,78});

数组中可被三整除的项目列表:

3

234

72

78



答案:

public static void main(String [] args){

//数据定义:

int [] intArray = {87,1938,13,689 ,12,54,37,86,21,98,97,92,3};

String garbage =glmcuaiuwblmcjcusiuhqmlmcdtyrns;







//必须符合的函数调用。

divThree(intArray);

System.out .println();

checkNumContain(lmc,垃圾);







}

public static void divThree(int [] intArray){

for(int i = 0;我< intArray.length; i ++){

if(intArray [0]%3 == 0){

System.out.println(intArray +可以被3整除);



}否则{



System.out.println(intArray +不能被3整除) ;



public static void checkNumContain(Stringlmc,String garbage){

checkNumContain(lmc,garbage);

}

}

}

}



< b>我尝试了什么:



因为它要求我检查数字是否可被3整除。我使用了模数。由于我是Java编程的新手,我仍然在努力解决它。

解决方案

嗯......看看你的代码,有两件事情可以解决错误的,一个主要的,两个相同的例子。

第一个很简单:

  for  int  i =  0 ; i< intArray.length; i ++) {
if (intArray [ 0 ]% 3 == 0 ){

只检查数组的第一个元素。也许如果你使用循环变量作为索引而不是零?



其他不太重要:

 System.out.println(intArray +  可以被3整理<​​/ span>); 





 System.out.println(intArray +  < span class =code-string>不能被3)整除; 

每个都尝试将整个数组打印为可整除或不可整除。同样,teh数组上的索引可能会有所帮助。


请参阅 Java™教程 [ ^ ]。

Problem:
You are expected to at least use a loop and conditional. Immediately when a number is found to be divisible by 3, print it out.
Note: The provided array, a1, can be used when calling the first function.
Sample run:
divThree({3,53,234,72,31,32,78});
List of items in the array divisible by three:
3
234
72
78

Answer:
public static void main(String[] args){
//Data definitions:
int[] intArray = {87,1938,13,689,12,54,37,86,21,98,97,92,3};
String garbage = "glmcuaiuwblmcjcusiuhqmlmcdtyrns";



//Function calls which must conform to.
divThree(intArray);
System.out.println();
checkNumContain("lmc",garbage);



}
public static void divThree(int[] intArray){
for (int i = 0; i < intArray.length; i++){
if(intArray[0] % 3 == 0){
System.out.println(intArray+ "is divisible by 3");

} else{

System.out.println(intArray+ "is not divisible by 3");

public static void checkNumContain(String "lmc", String garbage){
checkNumContain("lmc",garbage);
}
}
}
}

What I have tried:

As it asks me to check whether the numbers are divisible by 3. I used Modulus. As I am new to Java programming, I am still struggling with it.

解决方案

Um...look at your code, and there are two things that stick out as wrong, one major, and two examples of the same thing.
The first is simple:

for (int i = 0; i < intArray.length; i++){
if(intArray[0] % 3 == 0){

Only ever checks the first element of the array. Perhaps if you used the loop variable as an index instead of zero?

The others are less major:

System.out.println(intArray+ "is divisible by 3");


and

System.out.println(intArray+ "is not divisible by 3");

Each of these tries to print the whole array as divisible or not divisible. Again, an index on teh array would probably help.


See The Java™ Tutorials[^].


这篇关于我的问题出了问题。你们有人可以帮我解决这个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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