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.


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

Results 1 to 3 of 3

Thread: Having problems with basics

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Thanked 0 Times in 0 Posts

    Post Having problems with basics

    Hello, I started learning Java and I ran in to some troubles with the basics while I was trying to figure out some arrays.
    I wrote 2 for loops and I tried to make them identical as possible but the error on last line in the second loop says "n cannot be resolved to a variable"
    what seems to be the problem?

    public class apps {
    public static void main(String[] args) {

    String[] words = new String[3];
    words[0] = "Hello ";
    words[1] = "to ";
    words[2] = "you ";

    for(int i=0; i<3; i++)

    String[] bestSinger = new String[4];
    bestSinger[0] = "Billie ";
    bestSinger[1] = "Eilish ";
    bestSinger[2] = "kicks ";
    bestSinger[3] = "ass! ";

    for(int n=0; n<4; n++);


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Having problems with basics

    The print statement is outside of the for loop, so its control variable is not defined.
    The for statement (and most statements) ends with the ; that is after the )
    Remove the ; to include the print statement inside of the for loop
    It is better to Wrap the contents of the for loop with {}s
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2021
    Thanked 0 Times in 0 Posts

    Default Re: Having problems with basics

    Very helpful thanks alot!

Similar Threads

  1. CSC Basics - Final Program Problems
    By TylerJH7 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 3rd, 2013, 04:56 PM
  2. Java basics
    By tommyacton in forum Object Oriented Programming
    Replies: 5
    Last Post: January 5th, 2013, 07:39 AM
  3. I need help with basics.
    By Emperor_Xyn in forum Java Theory & Questions
    Replies: 8
    Last Post: December 5th, 2011, 05:09 AM
  4. [SOLVED] Basics With UDP Packet
    By servalsoft in forum Java Networking
    Replies: 0
    Last Post: October 13th, 2011, 12:47 PM
  5. Need a little help with the basics
    By Java Neil in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 17th, 2011, 10:54 PM