class AddThreeNumbers
{
public static int number1;
public static int number1;
public static int number3;
public static void main(int 1, int 2, int 3)
{
number1= 1;
number2=2;
number3=3;
}
public int Addition()
{
return(number1+number2+number3;
}
public static void main(String arg[])
{
AddThreeNumbers addthreenumbers = new AddThreeNumbers();
AddThreeNumbers.main(1,2,3);
int i= addthreenumbers.Addition();
System.out.println("value is="+ i);
}
}
public class stringCalc { //Public Class
public static void main(String[] args) { //Main
int arrInt[] = new int[3]; //Create integer with a maximum of three
arrInt[0] = 1; //Assign 1 as the default value
int i = 1; //Create integer "i" equal to "1"
while (i <= 2){ //While i is less than or equal to '2', perform the following
arrInt[i] = i+1; //If above is true, arrInt will add 1 to i.
i++; //This rules it out
} //Ends While
System.out.println(arrInt[0] + " + " + arrInt[1] + " + " + arrInt[2]); //Prints the value of the above
} //Ends main
} //Ends stringCalc
String stringNumber = "123";
double doubleNumber = Double.parseDouble(stringNumber);
String stringNumber = "123";
int intNumber = Integer.parseInt(stringNumber);
I'm not aware of any way to do that. Java recognises a string as being text so it doesn't do calculations on strings. Is there any reason why you would not want to convert your strings to ints or doubles and then do the calculations?JosephC said:...is it not possible to do this with +, -, * or / inside the string?...
Since 2007, Forum Promotion has specialized in providing advertising solutions to webmasters looking to promote their communities. We pride ourselves in being the bridge that connects forum administrators, bloggers, and more.
We use essential cookies to make this site work, and optional cookies to enhance your experience.