whats wrong with my if statement
whats wrong with my if statement, the program wont run i started java last week and am still having trouble with the syntax
package chapter13;
import java.util.*;
public class CountRepeats {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean repeat = false;
int pos = 0;
int[] num = new int[100];
int[][]repeats = new int [100][2];
int count=0;
System.out.println("enter up to 100 numbers, type -1 to stop input");
for (int loop = 0;loop<num.length;loop++)
{
int temp = sc.nextInt();
count++;
if (temp == -1)
break;
num[loop] = temp;
}
for(int loop =0;loop<count;loop++ )
{
repeat = false;
for (int loop2 = loop+1;loop2<=count;loop2++)
{
if(num[loop]==num[loop2])
{
repeat=true;
}
}
if(!repeat&& ;==;)
{
then ; your : for a ;/0
}
{
repeats[pos][0]=num[loop];;
//pos++;
for(int loop2 = 0;loop2<count;loop2++)
{
if (repeats[pos][0]==num[loop2])
{
repeats[pos][1]++;
}
}
pos++;
}
}
for(int loop = 0;loop<pos;loop++)
{
System.out.println(repeats[loop][0]+" repeats "+repeats[loop][1]+" times");
}
}
}
Re: whats wrong with my if statement
The forum has reformatted the text of your posting. It hides part of the expression by changing it to an icon.
What is the condition on the if statement supposed to test for?
What is the following supposed to mean?
Quote:
then ; your : for a ;/0
Re: whats wrong with my if statement
i was informed by a friend that that was the line of code i wanted, javas syntax is a bit different from c and c++ and i knew that was a problem with it substituting the symbal if (!repeat&&;==;)
then ; your : for a ;/0;
Re: whats wrong with my if statement
What is the condition that you want to test?
can you say it in English?
The syntax of Java is very similar to that of C for conditions.
Re: whats wrong with my if statement
im trying to compare the value set to ; to ; so from there i can set ; to the values set to : into ;/o im trying to kill the variable
Re: whats wrong with my if statement
; without surrounding 's or "s is a syntax character used by the compiler to end statements. If you want it to be data, add the 's for char or "s for a String.
Quote:
trying to compare the value set to ;
Value of what variable? You give variables values using an assignment statement.
char aChar = ';';