import java.util.Scanner;
public class LoopPatterns {

    /**
     * @param args
     */
    public static void main(String[] args) {
    public static double Largest {  
                Scanner s = new Scanner(System.in);
                int num, largest = 0;

                for ( int i = 1; i <= 10 ;i ++) {
                 System.out.print("Enter a number : ");
                 num = s.nextInt();
                 if ( num > largest)
                      largest = num;
                }
                System.out.println("Largest Number : " + largest);



    public static double First {

            String name1, name2, name3 ;
            boolean b, b1;
            int i, i1, i2,i3;
            Scanner keyboard = new Scanner(System.in);

            System.out.print("Enter first string: ");
            name1 = scan.nextLine();

            System.out.print("Enter second string: ");
            name2 = scan.nextLine();

            System.out.print("Enter third string: ");
            name3 = scan.nextLine();

            b = name1.equals(name2);
             // Check if identical ignoring case

    b1 = name1.equalsIgnoreCase(name2);

        i = name1.compareTo(name2);

    if (i < 0)
        {
            i1 = name1.compareToIgnoreCase(name3);

             if (i1 < 0)
                {
        System.out.println(name1);
        if (i1 > 0)
            {
            System.out.println(name3);
            i2 = name2.compareToIgnoreCase(name3);
                if (i2<0)
                {
                    System.out.println(name2);
                    System.out.println(name3);
                }
                if (i2>0)
                {
                    System.out.println(name3);
                    System.out.println(name2);
                }
                }
                }
    }
    else if (i > 0)
        {

            i1 = name2.compareToIgnoreCase(name3);

             if (i1 < 0)
                {
        System.out.println(name2);
        if (i1 > 0)
            {
            i2 = name1.compareToIgnoreCase(name3);
                if (i2<0)
                {
                    System.out.println(name1);
                    System.out.println(name3);
                }
                if (i2>0)
                {
                    System.out.println(name3);
                    System.out.println(name1);
                }
                }
                }
    }

                }
    }
    }

}

this is my code for calculating the largest number from a set of numbers and returing a string in reverse order what are my errors ?

Recommended Answers

All 5 Replies

what are my errors ?

Please post the full text of any error messages so we can see them.
Or if there are no error messages, please explain your problem.

The formatting for the posted code is very bad. Each nested pair of {}s should be indented 3-4 spaces so you can easily see the logic. There should not be a column of }s one under the other.

The ending "}" should be vertically in line beneath the line with the pairing "{"

For example:

  for(int i=0;i<A.length;i++){
    int c = 1;      // start with one

    for(int j=i+1;j<A.length;j++) {
      if (A[i]==A[j]) {
        c=c+1;
        System.out.println("c="+c +" A[i]="+A[i] + ", i=" + i + ", j="+j);
        if (c>(A.length/2)){
           return A[i];
        }
      }
    } //  end for(j)
  }  // end for(i)
import java.util.Scanner;

public class LoopPatterns {

    /**
     * @param args
     */
    public static void main(String[] args) {
        public static double Largest () {   
            Scanner s = new Scanner(System.in);
            int num, largest = 0;

            for ( int i = 1; i <= 10 ;i ++) {
                System.out.print("Enter a number : ");
                num = s.nextInt();
                if ( num > largest)
                    largest = num;
            }
            System.out.println("Largest Number : " + largest);



            public static double First (String name1, name2, name3 ;
                boolean b, b1;
                int i, i1, i2,i3;) {


                Scanner keyboard = new Scanner(System.in);

                System.out.print("Enter first string: ");
                name1 = keyboard.nextLine();

                System.out.print("Enter second string: ");
                name2 = keyboard.nextLine();

                System.out.print("Enter third string: ");
                name3 = keyboard.nextLine();

                b = name1.equals(name2);
                // Check if identical ignoring case

                b1 = name1.equalsIgnoreCase(name2);

                i = name1.compareTo(name2);

                if (i < 0)
                {
                    i1 = name1.compareToIgnoreCase(name3);

                    if (i1 < 0)
                    {
                        System.out.println(name1);
                        if (i1 > 0)
                        {
                            System.out.println(name3);
                            i2 = name2.compareToIgnoreCase(name3);
                            if (i2<0)
                            {
                                System.out.println(name2);
                                System.out.println(name3);
                            }
                            if (i2>0)
                            {
                                System.out.println(name3);
                                System.out.println(name2);
                            }
                        }
                    }
                }
                else if (i > 0)
                {

                    i1 = name2.compareToIgnoreCase(name3);

                    if (i1 < 0)
                    {
                        System.out.println(name2);
                        if (i1 > 0)
                        {
                            i2 = name1.compareToIgnoreCase(name3);
                            if (i2<0)
                            {
                                System.out.println(name1);
                                System.out.println(name3);
                            }
                            if (i2>0)
                            {
                                System.out.println(name3);
                                System.out.println(name1);
                            }
                        }
                    }
                }

            }
        }
    }
}

"line 25- illegal modifier for parameter first only final is permitted
line 12-illegal modifier for parameters only final is permitted
line 11-largest cannot be resorted to variable
line 11-syntax error on double @expected

Each arg in a methods definition must have a type, there is not a list of names with a type.
See: http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

A method can not be defined inside of another method. Code the ending "}" for one method before starting the definiton for the next method.

You should copy and paste the error messages, not type them in. The posted list of error messages has left off important information.

Dan, one tip I find helpful for beginners is to label the end brackets. For example:

public class AnyClass {

    public static void main(String[] args) {
        ...

    }//main

}//class
commented: Good idea. I use it a lot!!! +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.