Jump to content

Recommended Posts

Posted
Input ila undi
1 + 1 + 1
2 + 2
3 + 1 - 2
2 + 3 + 2
1 + 3 + 2 + 9
 
Output ila ravali 
1 + 1 + 1 = 3
2 + 2 = 4
3 + 1 - 2 = 2
2 + 3 + 2 = 7
1 + 3 + 2 + 9 = 15
 
Ela ?? Regular expression vadala ?? 

 

Posted


Input ila undi
1 + 1 + 1
2 + 2
3 + 1 - 2
2 + 3 + 2
1 + 3 + 2 + 9

Output ila ravali

1 + 1 + 1 = 3
2 + 2 = 4
3 + 1 - 2 = 2
2 + 3 + 2 = 7
1 + 3 + 2 + 9 = 15

Ela ?? Regular expression vadala ??


import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;

public class Test {
public static void main(String[] args) throws Exception{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "40+2";
System.out.println(engine.eval(foo));
}
}
  • Upvote 1
Posted

import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;

public class Test {
public static void main(String[] args) throws Exception{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "40+2";
System.out.println(engine.eval(foo));
}
}


Please note you need to have jdk1.6
Posted

import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;

public class Test {
public static void main(String[] args) throws Exception{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "40+2";
System.out.println(engine.eval(foo));
}
}

 

good one ...
to generalize we can make main logic into a method and pass every input as a parameter :)


import java.io.IOException;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class CSVParsing {

	 public static void main(String args[]) throws IOException
	 { 
		 
		 calculate("5+3");
	 }

	private static void calculate(String string) {
		 ScriptEngineManager mgr = new ScriptEngineManager();
		 ScriptEngine engine = mgr.getEngineByName("JavaScript");
		// String foo = "40+2";
		 try {
			System.out.println(engine.eval(string));
		} catch (ScriptException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}
}

Posted

Thanks a lot :)

This seems to be a simpler way...kani recursive loops like using for loop or while tho try chestunna ... trying to read the input and calculating the sun based on arithmetic operation.

 

Because if u use ScriptEngine  that will just calculate and throwing the out but I need to have output in this format

Input = Output 

 

1 + 1 + 1 = 3
2 + 2 = 4
3 + 1 - 2 = 2
2 + 3 + 2 = 7
1 + 3 + 2 + 9 = 15
 
ila undali ... so alantappudu .. I have to use the recursive loops kada .. is there any other way
Posted

 

Thanks a lot :)

This seems to be a simpler way...kani recursive loops like using for loop or while tho try chestunna ... trying to read the input and calculating the sun based on arithmetic operation.

 

Because if u use ScriptEngine  that will just calculate and throwing the out but I need to have output in this format

Input = Output 

 

1 + 1 + 1 = 3
2 + 2 = 4
3 + 1 - 2 = 2
2 + 3 + 2 = 7
1 + 3 + 2 + 9 = 15
 
ila undali ... so alantappudu .. I have to use the recursive loops kada .. is there any other way

 

 

 

learning lo vunnava ? If this ur assignment .. nuvvu adiginadhi simple task eh .. already pyna vunna code ni small modifications chesthe output ni nuvvu anukunna format lo present cheyochu .. try cheyyi ..

 

hint :  no need to use loops unless u need to give all the input parameters/exressions at a time ..

 

try chesi rapothe cheppu .. :)

Posted

learning lo vunnava ? If this ur assignment .. nuvvu adiginadhi simple task eh .. already pyna vunna code ni small modifications chesthe output ni nuvvu anukunna format lo present cheyochu .. try cheyyi ..

 

hint :  no need to use loops unless u need to give all the input parameters/exressions at a time ..

 

try chesi rapothe cheppu .. :)

 

Not learning working A ... but it's kind of assignment ... Thanks I will try

Posted

import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;

public class Test {
public static void main(String[] args) throws Exception{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "40+2";
System.out.println(engine.eval(foo));
}
}

akkada logic ee line lo undi ? ee java thoti idey problem... 

Posted

Not learning working A ... but it's kind of assignment ... Thanks I will try

 

 

S%Hi

Posted

learning lo vunnava ? If this ur assignment .. nuvvu adiginadhi simple task eh .. already pyna vunna code ni small modifications chesthe output ni nuvvu anukunna format lo present cheyochu .. try cheyyi ..

 

hint :  no need to use loops unless u need to give all the input parameters/exressions at a time ..

 

try chesi rapothe cheppu .. :)

 

GODDDDDDD ... inta silly question ... anyways I got it ... thanks innovative. 

Posted

akkada logic ee line lo undi ? ee java thoti idey problem... 

 

 

eval ane method lo vuntadhi ...

Posted

GODDDDDDD ... inta silly question ... anyways I got it ... thanks innovative. 

 

 

:D Good for you ...

Posted

eval ane method lo vuntadhi ...

eval() emi chesthadi ? its just evaluates the expression & displays the output ? 

Posted

What is expects man

Do u mean experts?


.g009_idi_amin_laughing_soldier.gif

engilpees lo weak anta man..odileyi .......ippudu oka english 101 class thesukoku porodiki...... 

×
×
  • Create New...