package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
//int sum, even, odd, min, max, size;
//int [] intArray;
//double average;
//int even = 0, odd = 0, min = 0, max = 0, size = 0, sum = 0;
//double average;
System.out.print("Please enter a number for the array size (zero or greater): ");
int n=in.nextInt();
if (n<0){
System.out.println("ERROR: Number must be at least zero!!!");
}else {
IntArray mainArray = new IntArray(n);
}
//com.company.IntMath intMath = new com.company.IntMath(average, even, odd, min, max, size, sum);
IntMath intMath = new IntMath();
//intMath.getAverage();
intMath.getEven();
intMath.getOdd();
intMath.getMin();
// intMath.getMax();
intMath.getSize();
intMath.getSum();
System.out.println("Average: " + intMath.getAverage() ); //print the average of the elements
System.out.println("Even Count: " + intMath.getEven()); //prints the count of all even numbers
System.out.println("Odd Count: " + intMath.getOdd()); //prints the count of all odd numbers
System.out.println("Min: " + intMath.getMin()); //prints the min number
//System.out.println("Max: " + intMath.getMax()); //prints the max number
System.out.println("Size: " + intMath.getSize()); //prints the size of the array
System.out.println("Sum: " + intMath.getSum()); //prints the sum of all elements
}
}
package com.company;
import java.util.Arrays;
import java.util.Random;
public class IntArray {
private int n;
private int [] intArray;
private double average;
private int sum;
private int even;
private int odd;
private int max;
private int min;
private int size;
public IntArray(int n) {
this.n = n;
Random randArray = new Random();
int[] intArray = new int[n];
intArray[0] = 0; //why does this not make the element 0 a 0?????????
for (int i = 0; i < n; i++) {
intArray[i] = randArray.nextInt(50); //I was getting very big random numbers, so I set the max to 50
}
System.out.println("Set: " + Arrays.toString(intArray));
}
public double getAverage() {
average = 0;
double total = 0;
for (int i = 0; i < n; i++) {
total = total + intArray[i];
}
return average;
}
public int getSum() {
//find the sum of all elements
sum = 0;
for (int i = 0; i < n; i++) {
sum += intArray[i];
}
return sum;
}
public int getEven() {
even = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 == 0) {
even++;
}
}
return even;
}
public int getOdd() {
odd = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 != 0) {
odd++;
}
}
return odd;
}
public int getMax() {
max = intArray[0];
for (int i = 1; i < n; i++) {
if (intArray[i] > max) {
max = intArray[i];
}
}
return max;
}
public int getMin() {
min = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < intArray.length; j++) {
if (intArray[i] > intArray[j]) {
min = intArray[i];
intArray[i] = intArray[j];
intArray[j] = min;
}
}
}
return min;
}
public int getSize() {
//find the size of the array
size = n + 1;
return size;
}
}
package com.company;
public class IntMath {
private double average;
private int sum;
private int even;
private int odd;
private int max;
private int min;
private int size;
private int[] intArray;
private int n;
//com.company.IntArray mainArray = new com.company.IntArray(n); //call IntArray to get variables ''n'' and ''intArray''
/*public IntMath(double average, int sum, int even, int odd, int max, int min, int size, int[] intArray) {
this.average = average;
this.sum = sum;
this.even = even;
this.odd = odd;
this.max = max;
this.min = min;
this.size = size;
this.intArray = intArray;
com.company.IntArray mainArray = new com.company.IntArray(n); //call IntArray to get variables ''n'' and ''intArray''
// average = 0;
// double total = 0;
// for (int i = 0; i < n; i++) {
// total = total + intArray[i];
// }
//find the sum of all elements
//sum = 0;
//for (int i = 0; i < n; i++) {
// sum += intArray[i];
//}
//find the count of the even numbers
//even = 0;
//for (int i = 0; i < n; i++) {
// if (intArray[i] % 2 == 0) {
// even++;
// }
//}
//find the count of the odd numbers
//odd = 0;
//for (int i = 0; i < n; i++) {
// if (intArray[i] % 2 != 0) {
// odd++;
// }
//}
//find the biggest number
//max = intArray[0];
//for (int i = 1; i < n; i++) {
// if (intArray[i] > max) {
// max = intArray[i];
// }
//}
//find the smallest number
//min = 0;
//for (int i = 0; i < n; i++) {
// for (int j = i + 1; j < intArray.length; j++) {
// if (intArray[i] > intArray[j]) {
// min = intArray[i];
// intArray[i] = intArray[j];
// intArray[j] = min;
// }
// }
/
//find the size of the array
//size = n + 1;
*/
public double getAverage() {
average = 0;
double total = 0;
for (int i = 0; i < n; i++) {
total = total + intArray[i];
}
return average;
}
public int getSum() {
//find the sum of all elements
sum = 0;
for (int i = 0; i < n; i++) {
sum += intArray[i];
}
return sum;
}
public int getEven() {
even = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 == 0) {
even++;
}
}
return even;
}
public int getOdd() {
odd = 0;
for (int i = 0; i < n; i++) {
if (intArray[i] % 2 != 0) {
odd++;
}
}
return odd;
}
public int getMax() {
max = intArray[0];
for (int i = 1; i < n; i++) {
if (intArray[i] > max) {
max = intArray[i];
}
}
return max;
}
public int getMin() {
min = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < intArray.length; j++) {
if (intArray[i] > intArray[j]) {
min = intArray[i];
intArray[i] = intArray[j];
intArray[j] = min;
}
}
}
return min;
}
public int getSize() {
//find the size of the array
size = n + 1;
return size;
}
}
在类Main中,如果初始化所有变量,该类将在编译时不会出错。
通过你的课程,我想你可能想做的是,
然后,该函数将使用API将一个json对象发送到数据库中,但似乎Volley.new请求队列(this);是一个空值。java.lang.NullPointerExcture:尝试在com.example.kevin.barcodescanner.addToCart.jsonParse的空对象引用上调用虚拟方法com.android.volley.请求com.android.volley.请求ue
你好,我尝试在ant中创建一个构建,如果它创建一个html报告,它将从eclips启动我的.class文件 “ “ 生成失败D:\Automation\Eclipse\MyWork\OpenCart\BUILD.xml:23:编译失败;有关详细信息,请参阅编译器错误输出。 总时间:1秒 ${lib}包含用于创建该类的所有库,并且只运行该类可以100%工作,但是当我试图在eclips中作为ant构建
常量express=require(“express”); 常量bodyParser=require(“body-parser”); 常量request=require('request'); 常量https=require(“https”); 常量app=express(); app.use(express.static(“public”)); app.use(BodyParser.URlenC
我匹配了所有的数据类型,但还是会出错 "不允许从数据类型'INT'到'CHAR'的隐式转换。使用CONVERT函数运行此查询。" 请导游。
Microsoft Windows[版本10.0.18363.778](c)2019 Microsoft Corporation。保留所有权利。 F:\flutter_projects\i_am_rich>flutter build apk您正在构建一个fat apk,它包含用于android-arm、android-arm64和Android-x64的二进制文件。如果您正在将应用程序部署到Pla
这是我的Fab活动 } 这是我的logcat 进程:com.teepe.teepe,PID:29259 java.lang.RuntimeException:无法启动活动组件Info{com.teepe.teepe/com.teepe.teepe.MainActivity}:java.lang.ClassCastException:Android.Support.Design.Widget.Flo