What is wrong with my code: public class Test { public static void main(String a
ID: 3761991 • Letter: W
Question
What is wrong with my code:
public class Test {
public static void main(String args[]}
int[] seq = {1, 2, 3, 4};
int totalOddDegree = 0;
int totalZeros = 0;
int seq.length = 0;
for (int i = 0; i < seq.length; i++){
System.out.print(seq[i] + " ");
}
for (int i = 0; i < seq.length; i++){
if(seq[i] > seq.length){
System.out.println("Fail");
break;
}
if (sequence[i]% 2! = 0){
totalOddDegree++;
}
if (sequence[i] < 0){
System.out.println("Fail");
break;
}
if (sequence[i] == 0){
totalZeros++;
}
int swap;
for (int n = 0; n < (seq.length - 1); n++){
for (int d = 0; d < seq.length - n - 1; d++) {
if (seq[d] > seq[d+1])
{
swap = seq[d];
seq[d] = seq[d+1];
seq[d+1] = swap;
}
}
}
for(int k = 0; k < seq.length; k++){
seq[k] = seq[k] - 1;
}
}
if(totalZeros == seq.length){
System.out.println("Success");
}
else if(totalOddDegree%2! = 0){
System.out.println("Fail");
}
else{
System.out.println("Success");
}
}
}
Explanation / Answer
Solution:
All errors removed.The program is as follows...
package com.chegg.nancy.solutions;
public class Test {
public static void main(String[] args) {
int[] seq = { 1, 2, 3, 4 };
int totalOddDegree = 0;
int totalZeros = 0;
for (int i = 0; i < seq.length; i++)
{
System.out.print(seq[i] + " ");
}
for (
int i = 0; i < seq.length; i++)
{
if (seq[i] > seq.length) {
System.out.println("Fail");
break;
}
if (seq[i] % 2 != 0) {
totalOddDegree++;
}
if (seq[i] < 0) {
System.out.println("Fail");
break;
}
if (seq[i] == 0) {
totalZeros++;
}
int swap;
for (int n = 0; n < (seq.length - 1); n++) {
for (int d = 0; d < seq.length - n - 1; d++) {
if (seq[d] > seq[d + 1]) {
swap = seq[d];
seq[d] = seq[d + 1];
seq[d + 1] = swap;
}
}
}
for (int k = 0; k < seq.length; k++) {
seq[k] = seq[k] - 1;
}
}
if (totalZeros == seq.length) {
System.out.println("Success");
} else if (totalOddDegree % 2 != 0) {
System.out.println("Fail");
} else {
System.out.println("Success");
}
}
}
Output:
1 2 3 4 Success
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.