Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: whats wrong with my if statement

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    }





  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?
    then ; your : for a ;/0

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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;

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    Last edited by semicolon; May 23rd, 2011 at 04:18 PM. Reason: misspelling

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.

    trying to compare the value set to ;
    Value of what variable? You give variables values using an assignment statement.
    char aChar = ';';

Similar Threads

  1. whats wrong?
    By whattheeff in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 25th, 2011, 02:35 PM
  2. could you tell me whats wrong....
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2010, 04:35 PM
  3. whats wrong with this one....
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 6th, 2009, 10:08 AM
  4. help whats wrong
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 3rd, 2009, 01:41 AM
  5. [SOLVED] whats wrong with my IDE
    By chronoz13 in forum Java IDEs
    Replies: 2
    Last Post: August 27th, 2009, 06:34 AM