import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public class Main { public static void main(String[] args) throws Exception { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("JavaScript"); // JavaScript code from String Object ob = scriptEngine.eval("9 + 15 + 30"); System.out.println("Result of evaluating mathematical expressions in String = "+ob); } }
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = { 50,60,70,80,90},v1; //declaring v(with values), v1 as vector. vector<int>::iterator iter; //declaring an iterator iter = v.insert(v.begin(), 40); //inserting a value in v vector before the beginning. iter = v.insert(v.begin(), 1, 30); //inserting a value with its size in v vector before the beginning. cout << "The vector1 elements are: \n"; for (iter = v.begin(); iter != v.end(); ++iter) cout << *iter << " "<<endl; // printing the values of v vector v1.insert(v1.begin(), v.begin(), v.end()); //inserting all values of v in v1 vector. cout << "The vector2 elements are: \n"; for (iter = v1.begin(); iter != v1.end(); ++iter) cout << *iter << " "<<endl; // printing the values of v1 vector return 0; }
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { map<char, int> m; //initialize a map map<char, int>::iterator iter; //initializing a map as iterator m.insert (pair<char, int>('a', 10)); //inserting values to the map m.insert (pair<char, int>('b', 20)); cout << "Elements in map:\n"; for (iter=m.begin();iter!=m.end();iter++) cout << "[ " << iter->first << ", "<< iter->second << "]\n"; //printing the values of the map return 0; }
#include <iostream> #include <queue> using namespace std; #define ROW 6 #define COL 3 struct student { //defining the student structure int roll,marks; student(int roll, int marks) : roll(roll), marks(marks) { } }; struct comparemarks{ // defining the comparemarks structure bool operator()(student const& s1, student const& s2) //overloading the operators of the student structure { return s1.marks < s2.marks; } }; int main() { priority_queue<student, vector<student>, comparemarks> M; // using the priority queue. // We have to use this type of syntax to use the priority queue. int a[ROW][COL] = {{15, 50}, {16, 60}, {18,70}, {14, 80}, {12, 90}, {20, 100}}; for (int i = 0; i < ROW; ++i) { M.push(student(a[i][0], a[i][1])); //inserting variables in the queue } cout<<"priority queue for structure ::"<<endl; while (!M.empty()) { student s = M.top(); M.pop(); cout << s.roll << " " << s.marks << "\n"; //printing the values } return 0; }
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { set<int> s; //Declaring an empty set container set<int>::iterator iter; //Declaring a set container as iterator which will point to the lower bound value s.insert(7); //inserting elements in the set container s s.insert(6); s.insert(1); s.insert(4); s.insert(2); s.insert(9); s.insert(10); iter = s.lower_bound(4); //passing a key by parameter to find its lower bound cout <<"The lower bound of 4 is: "<< *iter << " "<<endl; //printing the lowerbound value iter = s.lower_bound(5); cout <<"The lower bound of 5 is: " <<*iter << " "<<endl; iter = s.lower_bound(30); cout <<"The lower bound of 30 is: " <<*iter << " "<<endl; return 0; }
public class Sample { public static void main(String []args) { String s1 = "tutorialspoint"; String s2 = "tutorialspoint"; String s3 = new String ("Tutorials Point"); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); } }
import java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "tutorials", str2 = "point"; // comparing str1 and str2 int retval = str1.compareTo(str2); // prints the return value of the comparison if (retval < 0) { System.out.println("str1 is greater than str2"); } else if (retval == 0) { System.out.println("str1 is equal to str2"); } else { System.out.println("str1 is less than str2"); } } }
public class Sample{ public static void main(String []args){ String s1 = "tutorialspoint"; String s2 = "tutorialspoint"; String s3 = new String ("Tutorials Point"); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); } }
public class Test { public static void main(String args[]) { Integer x = 5; Integer y = 10; Integer z =5; Short a = 5; System.out.println(x.equals(y)); System.out.println(x.equals(z)); System.out.println(x.equals(a)); } }
import java.lang.*; public class StringBufferDemo { public static void main(String[] args) { StringBuffer buff = new StringBuffer("tuts "); System.out.println("buffer = " + buff); // appends the char argument as string to the string buffer. buff.append('A'); // print the string buffer after appending System.out.println("After append = " + buff); buff = new StringBuffer("abcd "); System.out.println("buffer = " + buff); // appends the char argument as string to the string buffer. buff.append('!'); // print the string buffer after appending System.out.println("After append = " + buff); } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more