Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

help!!

Thread view: 
fitz - 08 Oct 2006 15:23 GMT
hey guys, i'm new to java and i'm just learning so bear with me... i
have writted the following code but this gives two errors when
compiling but i can't see anything wrong with it... can someone give me
some pointers???

//This program compares a series of user inputs and determines the
smallest integer entered.
import java.util.Scanner;//program uses class scanner

public class SmallestInteger()
{{

    //procedures to find smallest integer from user inputs
    public void compareNumbers()
    {
        Scanner Input = new Scanner (System.in);

        int numberCounter;//number of data to be compared
        int inputNumber1;//number entered by user for comparison
        int inputNumber2;//number entered by user for comparison
        int smaller;//the smallest number

        //requests the user to enter an integer for comparison
        System.out.printf("Please specify the number of integers for
comparison or enter -1 to exit:%d",numberCounter);
        numberCounter = input.nextInt();//stores the user input as
numberCounter

        //loop until sentiel value is entered
        while (numberCounter!= -1)
        {
            //requests the user to enter a number for comparison
            System.out.printf("\n\nPlease enter number for
comparison:%d",inputNumber1);
            inputNumber1 = input.nextInt();//stores the input by the user as
inputNumber1
            numberCounter--;//decrements the counter by one

            //loops when numberCounter remains positive
            for (;numberCounter=0;)
            {
                //requests the user to enter a number for comparison
                System.out.printf("\n\nPlease enter next number for
comparison:%d",inputNumber2);
                inputNumber2 = input.nextInt();//stores the input by the user as
inputNumber2
                numberCounter--;//decrements the counter by one

                //informs user about number of data left to input
                System.out.prinf("\n\n%d numbers left\n\n",numberCounter);

                //compares the number entries
                //in case of inputNumber1 larger or equal to inputNumber2
                if (inputNumber1>=inputNumber2)
                {
                    smaller=inputNumber2;//stores inputNumber2 as smaller
                }
                //in case of inputNumber1 smaller than inputNumber2
                else if(inputNumber1<inputNumber2)
                {
                    smaller=inputNumber1;//stores inputNumber1 as smaller
                }

                //requsts the user to enter the next number for comparison
                System.out.printf("\n\nPlease enter next number for
comparison:%d",inputNumber1);
                inputNumber1= input.nextInt();//stores input as inputNumber1
                numberCounter--;

                //informs user about number of data left to input
                System.out.printf("\n\n%d numbers left\n\n",numberCounter);
            }
                //outputs the smallest number from comparison
                System.out.printf("\n\nThe smallest number is:%d",smaller);

                System.out.println("\n\nThanks for your time!\n\n");
        }
        System.out.println("Program terminated\n\n");
    }
}
}
Lee Weiner - 08 Oct 2006 15:47 GMT
>hey guys, i'm new to java and i'm just learning so bear with me... i
>have writted the following code but this gives two errors when
[quoted text clipped - 7 lines]
>public class SmallestInteger()
>{{

1. Take out the parentheses on the class declaration line:

2. You've got double braces at the beginning and end of the class. Take one
out in each place.

public class SmallestInteger
{

BTW, when you correct these two, you'll find about 6 other syntax errors.

Lee Weiner
lee AT leeweiner DOT org
IchBin - 09 Oct 2006 01:20 GMT
> hey guys, i'm new to java and i'm just learning so bear with me... i
> have writted the following code but this gives two errors when
[quoted text clipped - 4 lines]
> smallest integer entered.
> import java.util.Scanner;//program uses class scanner

[snip code]

I have not tested but cleaned up all your compiler errors. You may want
to compare to your version. I am not testing because it is your class
assignment being done on a Sunday night.

import java.util.Scanner;
public class SmallestInteger
{
    // procedures to find smallest integer from user inputs
    public void compareNumbers()
    {
        Scanner Input = new Scanner (System.in);

        int numberCounter     = 0;    // number of data to be compared
        int inputNumber1     = 0;    // number entered by user for comparison
        int inputNumber2     = 0;    // number entered by user for comparison
        int smaller            = 0;    // the smallest number

        // requests the user to enter an integer for comparison
        System.out.printf("Please specify the number of integers for
comparison or enter -1 to exit:%d",
                            numberCounter);
        numberCounter = Input.nextInt();    // stores the user input as    numberCounter

        // loop until sentiel value is entered
        while (numberCounter!= -1)
        {
            // requests the user to enter a number for comparison
            System.out.printf("\n\nPlease enter number for
comparison:%d",inputNumber1);
                    inputNumber1 = Input.nextInt();    // stores the input by the
                                                    // user as inputNumber1
            numberCounter--;// decrements the counter by one

            // loops when numberCounter remains positive
             while (numberCounter==0)
            {
                // requests the user to enter a number for comparison
                System.out.printf("\n\nPlease enter next number for
comparison:%d",inputNumber2);
                inputNumber2 = Input.nextInt();        // stores the input by
                                                    // the user as inputNumber2
                numberCounter--;                    // decrements the counter by one

                // informs user about number of data left to input
                System.out.printf("\n\n%d numbers left\n\n", numberCounter);

                // compares the number entries
                // in case of inputNumber1 larger or equal to inputNumber2
                if (inputNumber1>=inputNumber2)
                {
                    smaller=inputNumber2;// stores inputNumber2 as smaller
                }
                // in case of inputNumber1 smaller than inputNumber2
                else if(inputNumber1<inputNumber2)
                {
                    smaller=inputNumber1;// stores inputNumber1 as smaller
                }
                // requsts the user to enter the next number for comparison
                System.out.printf("\n\nPlease enter next number for
comparison:%d",inputNumber1);
                inputNumber1= Input.nextInt();// stores input as inputNumber1
                numberCounter--;

                // informs user about number of data left to input
                System.out.printf("\n\n%d numbers left\n\n",numberCounter);
            }
            // outputs the smallest number from comparison
            System.out.printf("\n\nThe smallest number is:%d",smaller);

            System.out.println("\n\nThanks for your time!\n\n");
        }
        System.out.println("Program terminated\n\n");
    }
}

Signature

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.