Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing Strings to Integers  RSS feed

 
Reed Spool
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty new to programming and I'm a highschool student. I have a math class this semester. I want to make a few simple programs, or maybe one program that take a couple input values and spits out some other values. Let's say i enter:
%java Pythagorean 3 4
i would like it to print:
The third side is 5.
I have everything down except taking that number input and making java think it's an Integer. I did this easily with VB because i could tell it to change the value of the command box from a string to an integer. I tried changing the main to be
public static void main(Integer[] args)
but the compiler whined. i also tried
public static void main(int[] args)
but more whining was to be had.
I would love hints more then a flat out answer, unless there's no way to get it! ty ty in advance
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't change the parameters to main -- it is how the java will call the initial class. If you do, it won't find the main method to call.

Anyway, you can change the parameters strings to ints or Integer via the parse methods available in the Integer class. Do it after the strings are passed to the main method.

Henry
[ February 08, 2006: Message edited by: Henry Wong ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!