int to string help

6 posts Page 1 of 1
Contributors
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

int to string help
Bogoh67
ok so i have this
Code: Select all
String fn = JOptionPane.showInputDialog("Enter your first number");
		String sn = JOptionPane.showInputDialog("Enter your second number");
		String op = JOptionPane.showInputDialog("Enter either divide(1), multiply(2), subtract(3), add(4)");
		if (op<1){
			JOptionPane.showMessageDialog(null, "Not Applicable, must use numeral character or number may not be smaller than 1", "ERROR", JOptionPane.ERROR_MESSAGE);		
		}
		if (op>4){
			JOptionPane.showMessageDialog(null, "Not Applicable, must use numeral character or number may not be larger than 4", "ERROR", JOptionPane.ERROR_MESSAGE);			
		}
		
		switch (op){
		case 1:
			
		}
and you see where it says "String op" i dont want the variable op to be a String i want it to be a int or if i cant

how can i use switch with a string, not a number


btw im betting at least 6 bucks that mandai, zulf, or mike will answer the best :)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: int to string help
mandai
You should use this (C#):
Code: Select all
int number = int.Parse(op);
Is there a particular reason why this is in the JavaScript section? If this was JavaScript you would not need to worry about parsing as there are no strict rules on data types.
Last edited by mandai on Thu Aug 04, 2011 1:44 pm, edited 1 time in total.
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: int to string help
comathi
Use
Code: Select all
convert.tostring(whatever your int is)


to convert from an int to a string

or
Code: Select all
convert.toint32(your string here)
to convert from string to an int.

Hope this helps :D


Edit: Oh wait, are you doing this in VB.NET?
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: int to string help
Bogoh67
no this is java_script and mandai i swear this is truly java-script but the program i use to program is eclipse but it keeps saying that its wrong and i cant
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Re: int to string help
mikethedj4
Bogoh67 wrote:
no this is java_script and mandai i swear this is truly java-script but the program i use to program is eclipse but it keeps saying that its wrong and i cant
Dude Javascript, and Java are two completely different programming languages. Maybe you should take a look at this topic I posted on the Evolution of Computer Programming Languages.

Now by looking at your code it's Java, not Javascript, and that means this post belongs here.

Also I see your code is similar to one of the first Java tutorials I watched by Bucky (thenewboston) when you ever get into gui development. Here's something to get you started. (It's just a window, but once you get better you can add a file menu, images, etc:)
Code: Select all
import javax.swing.JFrame;

public class app {
	public static void main(String [] args) {
		new tapp();
	}

	private static class tapp extends JFrame {
		public tapp() {
			super();
			setTitle("TestApp");
			setSize(320,240);
			setLocationByPlatform(true);
			setAlwaysOnTop(false);
			setVisible(true);
			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}
	}
}
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: int to string help
Bogoh67
excuse me for my newbieness then , and thanks for sharing the code!!!!
6 posts Page 1 of 1
Return to “Tutorials”