.class expected error

need some help with program

Page 1 of 1

5 Replies - 20129 Views - Last Post: 03 November 2008 - 09:07 PM Rate Topic: -----

#1 grayzer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-November 08

.class expected error

Posted 03 November 2008 - 02:30 PM

Hi there,

just new to java and trying to do the following task:

Write a program which will take in two integer numbers as integer parameters from 'main'. e.g. main (int num1, int num2)
Your program should do the following:

1) print out the larger of the two numbers.

2) if they are equal, print out that they are equal

3) if either or both number is greater than 100, print out which one(s) are

4) if either number is less than zero, print "number must be zero or higher"

5) test your program to ensure it works for various combinations of input
Submit the program

I've wrote the program but I get a '.class' expected when I compile - can anybody help cos I'm new to this?

here's my program below:
public class comparison
{
	public static void main(int num1, int num2)
	{
	  if (int num1 > int num2)
			System.out.println("int num1" is larger);
		else if (int num2 > int num1)
			System.out.println("int num2" is larger);
			else if (int num1 = int num2)
			System.out.println(''numbers are equal'');
			else if ((int num1 || int num2) || (int num1 && int num2) > 100)
			System.out.println.(''numbers are greater than 100'');
			else if (int num1 || int num2 < 0)
			System.out.println(''number must be zero or higher'');
			
		 
	}



Is This A Good Question/Topic? 0
  • +

Replies To: .class expected error

#2 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1147
  • View blog
  • Posts: 7,133
  • Joined: 07-September 06

Re: .class expected error

Posted 03 November 2008 - 02:34 PM

Please don't post questions in the introduction section.

Moved to java.
Was This Post Helpful? 1
  • +
  • -

#3 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Re: .class expected error

Posted 03 November 2008 - 02:47 PM

Holy lazy on braces much? Always use braces, even for one-liners. It is easier to read and it is a good habit to get into.

public class comparison{
   public static void main(int num1, int num2){
      if (int num1 > int num2){
         System.out.println("int num1" is larger);
      }
      else if (int num2 > int num1){
         System.out.println("int num2" is larger);
      }
      else if (int num1 = int num2){
          System.out.println(''numbers are equal'');
      }
      else if ((int num1 || int num2) || (int num1 && int num2) > 100){
           System.out.println.(''numbers are greater than 100'');
      }
      else if (int num1 || int num2 < 0){
         System.out.println(''number must be zero or higher'');
      }
   }
}



Good Luck!
Was This Post Helpful? 0
  • +
  • -

#4 grayzer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 03-November 08

Re: .class expected error

Posted 03 November 2008 - 03:18 PM

Hi Stauffski,

even when i put in the braces I'm still getting the '.class' expected error up.

grayzer

View Poststauffski, on 3 Nov, 2008 - 01:47 PM, said:

Holy lazy on braces much? Always use braces, even for one-liners. It is easier to read and it is a good habit to get into.

public class comparison{
   public static void main(int num1, int num2){
      if (int num1 > int num2){
         System.out.println("int num1" is larger);
      }
      else if (int num2 > int num1){
         System.out.println("int num2" is larger);
      }
      else if (int num1 = int num2){
          System.out.println(''numbers are equal'');
      }
      else if ((int num1 || int num2) || (int num1 && int num2) > 100){
           System.out.println.(''numbers are greater than 100'');
      }
      else if (int num1 || int num2 < 0){
         System.out.println(''number must be zero or higher'');
      }
   }
}



Good Luck!

Was This Post Helpful? 0
  • +
  • -

#5 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Re: .class expected error

Posted 03 November 2008 - 03:59 PM

Haha, wow. It's so obvious I missed it a few times. Remove all the "int" phrases from the if statements. That should do it.

Good Luck!

Oh, also... Did you check your quotes in the print line?
Once again get rid of the "int" phrases, and don't quote the variable. Quote the text. Make sure there is a "+" in between each variable in the print statement.

One more thing. When comparing with "=," it needs to be "==." "=" assigns values, "==" compares values. Fix that and then you should be good to go :D
Was This Post Helpful? 1
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: .class expected error

Posted 03 November 2008 - 09:07 PM

The signature of main()

public static void main(String[] arg)

you cannot switch it to (int i, int j)

you will have to:

public static void main(String[] arg) {
   myMain(100, 200);
}

public static void myMain(int i, int j) {
   .... do you stuff here
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1