11 Replies - 1448 Views - Last Post: 13 October 2006 - 12:27 PM Rate Topic: -----

#1 Marine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-September 06

Application Version not working

Posted 13 October 2006 - 07:16 AM

Hi!
I started to learn java and was trying to write simple programs. Two similar programs but one of them is not working. Maybe somebody can explain me why?

This doesn't work:
public class Ex
{ 
   public static void main(String[] args) 
   { 
		int number; 
		int second_power; 
		int third_power; 

		System.out.print ("Give the number: "); 
		number = .readInt(); 

		second_power=number*number; 
		third_power=number*number*number; 

		System.out.println ("Number="+number); 
		System.out.println ("Second_power=" +second_power); 
		System.out.println ("Third_power=" +third_power); 
	} 
} 



and this works:

public class Ex 
{ 
   public static void main(String[] args) 
   { 
		int number; 
		int second_power; 
		int third_power; 

		System.out.print ("Give the number: "); 
		number = .readInt(); 

		second_power=number*number; 
		third_power=number*number*number; 

		System.out.println ("Number="+number); 
		System.out.println ("Second_power=" +second_power); 
		System.out.println ("Third_power=" +third_power); 
	} 
} 



Is This A Good Question/Topic? 0
  • +

Replies To: Application Version not working

#2 nickypoo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-October 06

Re: Application Version not working

Posted 13 October 2006 - 07:28 AM

Is this a trick question? It feels like im playing the "Whats different about these two pictures" game and i suck at that game.
Are these in two seperate applications?
What IDE are you using? It should have some kind of compiler that will show you the errors if the app is breaking.

This post has been edited by nickypoo: 13 October 2006 - 07:30 AM

Was This Post Helpful? 0
  • +
  • -

#3 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Application Version not working

Posted 13 October 2006 - 07:30 AM

I'm not sure what you mean by 'not working' but the first version of your application is not likely to compile, as there is no top level class specified.

when you say 'not working', what exactly do you mean? Wuill not compile? Compiles but does not run as expected? Are you getting any error messages? If so, can you post them?
Was This Post Helpful? 0
  • +
  • -

#4 Marine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-September 06

Re: Application Version not working

Posted 13 October 2006 - 07:54 AM

mmm:)

These are two separate programs but have to print the same information. This program I can compile and run.
public class Ex_1_020
{
	public static void main (String[] ssss)
	{
		// DEFINITIONS
		int number;
		int power2;
		int power3;

		// START

		System.out.print("Give number: ");
		number = Keyboard.readInt();

		power2 = number * number;
		System.out.println("2nd power =" +power2);

		power3 = power2 * number;
		System.out.println("3rd power =" +power3);

		// END
	}
}



And when I try to compile second program it says: "Cannot find symbol variable Keyboard"
public class task_1_020
{
	public static void main(String[] ssss)
	{
		int number;
		int second_power;
		int third_power;

		System.out.print ("Give the number: ");
		number = Keyboard.readInt("Give the numver: ");

		second_power=number*number;
		System.out.println ("Second_power=" +second_power);

		third_power=number*number*number;
		System.out.println ("Third_power=" +third_power);
	}
 }

Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Application Version not working

Posted 13 October 2006 - 08:23 AM

Have you imported any librairies at the beginning of your code? I'm not intimately familiar with the Keyboard class..is it an external library? Are you compiling the two programs using the same compiler/platform setup?
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Application Version not working

Posted 13 October 2006 - 08:43 AM

I'm surprised either one of your programs compile, I'm curious as to what IDE you are using?

Neither one will compile in JCreator with JDK 5.0. According to the Java API there is not a Keyboard class.

I am going to make an assumption based on what it looks like you are trying to do. It looks like you are trying to use the Scanner class to read input of a type integer from the keyboard and store it in your variable.

You need to first import the Scanner class, then instantiate a Scanner object that is tied to the keyboard. Lastly readInt() is not a method that I am familiar with, I think your intention was to use nextInt() from the Scanner class.

Should look like this:
import java.util.Scanner;

public class Ex_1_020
{
	public static void main (String[] ssss)
	{
		// DEFINITIONS
		int number;
		int power2;
		int power3;

		  Scanner keyboard = new Scanner(System.in);
		// START

		System.out.print("Give number: ");
		number = keyboard.nextInt();

		power2 = number * number;
		System.out.println("2nd power = " +power2);

		power3 = power2 * number;
		System.out.println("3rd power = " +power3);

		// END
	}
}

Was This Post Helpful? 0
  • +
  • -

#7 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Application Version not working

Posted 13 October 2006 - 09:00 AM

Hmmm...it may be part of his course. I've been able to locate a Keyboard class here:

http://duke.csc.vill...es/keyboard.jsp

http://www.cs.uga.ed...1/keyboard.html

It is an external class written to help students with their programs..and readInt() is one of it's methods. Perhaps the user is including this class or has it installed as part of their academic program.
Was This Post Helpful? 0
  • +
  • -

#8 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Application Version not working

Posted 13 October 2006 - 09:18 AM

Good point, I wasn't thinking that it was a provided class. Perhaps this was written before the Scanner class was included in JDK.

Good catch, Amadeus.
Was This Post Helpful? 0
  • +
  • -

#9 Marine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-September 06

Re: Application Version not working

Posted 13 October 2006 - 11:37 AM

Thank you Amadeus and jayman9)))

I'm not familiar with Scanner class).
Just I still can't understand why one of this programs is not working,hm.
Was This Post Helpful? 0
  • +
  • -

#10 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Application Version not working

Posted 13 October 2006 - 11:43 AM

This is the problem with the second program.
number = Keyboard.readInt("Give the numver: ");


According to the link provided by Amadeus, the readInt method does not take an argument. And you are trying to pass in a String literal "Give the numver: ". Remove the string and it should work just fine.

Basically the error message is saying that it cannot find a method of readInt() that takes this argument in the Keyboard class.
Was This Post Helpful? 0
  • +
  • -

#11 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Application Version not working

Posted 13 October 2006 - 12:04 PM

Nicely diagnosed, jayman.
Was This Post Helpful? 0
  • +
  • -

#12 Marine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-September 06

Re: Application Version not working

Posted 13 October 2006 - 12:27 PM

:)
Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1