We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,466 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

keep getting errors for my program

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 ?

3
Contributors
5
Replies
12 Hours
Discussion Span
8 Months Ago
Last Updated
6
Views
dantheman4
Newbie Poster
19 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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)
NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
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

dantheman4
Newbie Poster
19 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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
Starstreak
Light Poster
48 posts since Aug 2012
Reputation Points: 13
Solved Threads: 10
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0809 seconds using 2.76MB