hgn330 ππ
Open in Telegram
Projects with source code | Android | java |website development | Website : https://updategadh.com Admin https://t.me/Rishabhsaini0204 New project https://www.youtube.com/c/decodeit2 Buy ads: https://telega.io/c/projectswithsourcecode
Show more4 310
Subscribers
No data24 hours
-587 days
-28130 days
Posts Archive
4 310
We are sharing the source Code
Electricity Bill projects in C++
On 25 jan 2020 !
ππππππππ
Stay connected
4 310
DRAW ππ\n");
p1 = 0;
p2 = 0;
}
end:
again:
printf("\n");
printf("Write 1 for play again\n");
printf("Write 2 for Quite\n");
scanf("%d",&a);
printf("\n");
printf("***********************\n");
printf("\n");
if(a==1){
goto label;
}
else if(a==2){
goto finish;
}
else{
goto again;
}
finish:
printf("πTHANKS FOR PLAYING \n");
return 0;
}
4 310
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main()
{ int num,random,a,n;
int i = 0;
int p1 = 0;
int p2 = 0;
char name[100];
printf(" ~ Welcome to Game ~\n");
printf("\n");
printf("Enter Your name : ");
gets(name);
printf("\n");
printf("Enter how many times u want to play :");
scanf("%d",&n);
printf("\n");
label:
while(i<n){
printf("turn %d Β»\n",i+1);
printf("\n");
printf("0 for Rock β\n");
printf("1 for Paper ποΈ\n");
printf("2 for scissorsβοΈ\n");
printf("\n");
printf("Choose what u want : ");
scanf("%d",&num);
srand(time(NULL));
random = rand()%3;
printf("\n");
switch(num)
{
case 0:
if(random == 0){
printf("You choose = ROCK\n");
printf("Computer choose = ROCK\n");
printf("\n");
printf("β vs β\n");
printf("\n");
printf("TIE!! (no-one got any point)\n");
printf("____________________________");
printf("\n");
printf("\n");
}
else if(random == 1){
printf("You choose = ROCK\n");
printf("Computer choose = PAPER\n");
printf("\n");
printf("β vs π\n");
printf("\n");
printf("COMPUTER GOT A POINT\n");
printf("____________________________");
printf("\n");
printf("\n");
p2++;
}
else if(random == 2){
printf("You choose = ROCK\n");
printf("Computer choose = SCISSORS\n");
printf("\n");
printf("βοΈ vs β\n");
printf("\n");
printf("YOU GOT A POINT\n");
printf("____________________________");
printf("\n");
printf("\n");
p1++;
}
break;
case 1:
if(random == 0){
printf("You choose = PAPER\n");
printf("Computer choose = ROCK\n");
printf("\n");
printf("π vs β\n");
printf("\n");
printf("YOU GOT A POINT\n");
printf("____________________________");
printf("\n");
printf("\n");
p1++;
}
else if(random == 1){
printf("You choose = PAPER\n");
printf("Computer choose = PAPER\n");
printf("\n");
printf("π vs π\n");
printf("\n");
printf("TIE!! (no-one got any point)\n");
printf("____________________________");
printf("\n");
printf("\n");
}
else if(random == 2){
printf("You choose = PAPER\n");
printf("Computer choose = SCISSORS\n");
printf("\n");
printf("π vs β\n");
printf("\n");
printf("COMPUTER GOT A POINT\n");
printf("____________________________");
printf("\n");
printf("\n");
p2++;
}
break;
case 2:
if(random == 0){
printf("You choose = SCISSORS\n");
printf("Computer choose = ROCK\n");
printf("\n");
printf("β vs β\n");
printf("\n");
printf("COMPUTER GOT A POINT\n");
printf("____________________________");
printf("\n");
printf("\n");
p2++;
}
else if(random == 1){
printf("You choose = SCISSORS\n");
printf("Computer choose = PAPER\n");
printf("\n");
printf("β vs ποΈ\n");
printf("\n");
printf("YOU GOT A POINT\n");
printf("____________________________");
printf("\n");
printf("\n");
p1++;
}
else if(random == 2){
printf("You choose = SCISSORS\n");
printf("Computer choose = SCISSORS\n");
printf("\n");
printf("βοΈ vs βοΈ\n");
printf("\n");
printf("TIE!! (no-one got any point)\n");
printf("____________________________");
printf("\n");
printf("\n");
}
break;
default:
printf("\n");
printf("You Give a wrong command π
\n");
printf("= = = = = = = = = = = =\n");
goto end;
break;
}
i++;
getchar();
}
i = 0;
printf(" β~RESULTS~β\n");
printf("\n");
if(p1<p2){
printf("%s Score is = %d",name,p1);
printf("\n");
printf("Computer Score is = %d\n",p2);
printf("\n");
printf("COMPUTER WON THE MATCH π»π\n");
p1 = 0;
p2 = 0;
}
else if(p2<p1){
printf("%s Score is = %d",name,p1);
printf("\n");
printf("Computer Score is = %d\n",p2);
printf("\n");
printf("YOU WON THE MATCH ππ\n");
p1 = 0;
p2 = 0;
}
else if(p1==p2){
printf("%s Score is = %d",name,p1);
printf("\n");
printf("Computer Score is = %d\n",p2);
printf("\n");
printf("THE MATCH IS
4 310
var attach = function(target, functionref, tasktype){
tasktype=(window.addEventListener)? tasktype : "on"+tasktype;
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
};
attach(window, function(){init()}, "load") ;
attach(document, function(){buttonTouchEnd()}, "mouseup") ;
return{
init: init,
generate: generate,
clear: clear
}
}());
4 310
}
buttonTouchStart(this)
};
buttonTag.ontouchstart = function(e){
if (!e) e = window.event;
e.preventDefault();
buttonTouchStart(this)
};
buttonTag.onmouseover = function(){buttonTouchOver(this)};
buttonTag.ontouchmove = buttonTouchMove;
buttonTag.onmouseup = function(){buttonTouchEnd(this)};
buttonTag.ontouchend = function(){buttonTouchEnd()};
}
buttons.push(buttonTag);
buttonsTag.appendChild(buttonTag);
}
patternTag.appendChild(buttonsTag);
// stupid preloader for the hover images
var imgTag = document.createElement("div");
imgTag.style.display = 'none';
imgTag.className = "patternlockbutton touched";
patternTag.appendChild(imgTag);
imgTag = document.createElement("div");
imgTag.style.display = 'none';
imgTag.className = "patternlockbutton touched multiple";
patternTag.appendChild(imgTag);
pel.appendChild(patternTag);
if (showResetButton){
var reset = document.createElement("div");
reset.className = "patternreset";
reset.style.display = "none";
reset.innerHTML = "(reset)";
reset.onclick = function(){
clear();
};
resets.push(reset);
pel.appendChild(reset);
}
};
var buttonTouchStart = function(b){
isdrawing = true;
if (inputbox.value != "") clear();
b.className = "patternlockbutton touched";
from = "";
to = b.id.split("patternlockbutton").join("");
inputbox.value = to;
startbutton = to;
return false;
};
var buttonTouchOver = function(b){
if (isdrawing){
var thisbutton = b.id.split("patternlockbutton").join("");
if(thisbutton != to){ // touching the same button twice in a row is not allowed (should it ?)
var cn = b.className;
if(cn.indexOf('touched')<0){
b.className = "patternlockbutton touched"
}else{
b.className = "patternlockbutton touched multiple"
}
from = to;
to = thisbutton;
//update input value
inputbox.value += to;
// display line between 2 buttons
var thisline = document.getElementById("line" + from + to);
if (to < from){
thisline = document.getElementById("line" + to + from);
}
if (thisline){
thisline.style.visibility = 'visible';
}
}
}
return(false)
};
var buttonTouchMove = function(e){
if(e.touches.length == 1){
var touch = e.touches[0];
processTouchMove(parseInt(touch.pageX),parseInt(touch.pageY));
}
};
var processTouchMove = function(x,y){
// find position relative to first button
if (!gridsize){
buttons[0].pos = findPos(buttons[0]);
buttons[1].pos = findPos(buttons[1]);
gridsize = parseInt(buttons[1].pos.left) - parseInt(buttons[0].pos.left);
}
var cox = x - parseInt(buttons[0].pos.left);
var coy = y - parseInt(buttons[0].pos.top);
// on what button are we over now?
// grid 3x3 to sequential nummber
var buttonnr = Math.min(2,Math.max(0,Math.floor(cox/gridsize))) + (Math.min(2,Math.max(0,Math.floor(coy/gridsize)))*3) + 1;
if (buttonnr != to){
// only trigger if the touch is near the middle of the button
// otherwise diagonal moves are impossible
var distancex = (cox % gridsize);
var distancey = (coy % gridsize);
if ((distancex< (gridsize/2)) && (distancey < (gridsize/2))){
// we're over a new button
var newButton = buttons[buttonnr-1];
buttonTouchOver(newButton);
}
}
};
var buttonTouchEnd = function(){
if (isdrawing){
isdrawing = false;
gridsize = false; // set to false so on the next touch it's recalculated as the layout could have been changed
if (autoSubmit){
var doSubmit = true;
if (document.forms[0].onsubmit){ doSubmit = document.forms[0].onsubmit() }
if(doSubmit){
document.forms[0].submit();
}
}
}
return(false)
};
// clears the patternlock;
var clear = function(){
var i,len;
for (i= 0, len=buttons.length; i<len; i++){
buttons[i].className = "patternlockbutton";
}
for (i= 0, len=lines.length; i<len; i++){
lines[i].style.visibility = 'hidden';
}
inputbox.value = "";
};
// helper function to find the absolute position of an element
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return {left: curleft,top: curtop};
}
4 310
// Pattern locks in j.s
//
var patternLock = (function () {
// Parameters-------------------
var autoInit = true;
var autoSubmit = true;
var showResetButton = true; // only applicable if autoSubmit is set to false or there's no submit button in the form;
// Code-------------------------
var isdrawing = false;
var from = "";
var to = "";
var inputbox;
var startbutton = 0;
var gridsize = false;
var buttons = []; // array to hold the 9 buttons
var lines = []; // array to hold the connecting lines
var resets = []; // array to hold the reset buttons
var init = function(){
if (autoInit){
var canAutosubmit = false;
var pw = document.getElementsByTagName("input");
for (var i=0;i<pw.length;i++){
if(pw[i].className == 'patternlock'){
generate(pw[i]);
}
if((pw[i].type=='submit') && (autoSubmit)){
pw[i].style.display = 'none';
canAutosubmit = true;
}
}
if (showResetButton && !canAutosubmit){
// show reset buttons
autoSubmit = false;
for (var r=0;r<resets.length;r++){
resets[r].style.display = "block";
}
}
}
};
var generate= function(el){
inputbox = el;
el.style.display = 'none';
var pel = el.parentNode;
// main container
var patternTag = document.createElement("div");
patternTag.className = "patternlockcontainer";
// horizontal lines
var linesTag = document.createElement("div");
linesTag.className = "patternlocklineshorizontalcontainer boxsizingcontentbox";
var elid=["12","23","45","56","78","89"];
for (var i=0;i<6;i++){
var lineTag = document.createElement("div");
lineTag.className = "patternlocklinehorizontal boxsizingcontentbox";
lineTag.id = "line" + elid[i];
lines.push(lineTag);
linesTag.appendChild(lineTag);
}
patternTag.appendChild(linesTag);
// vertical lines
linesTag = document.createElement("div");
linesTag.className = "patternlocklinesverticalcontainer boxsizingcontentbox";
elid=["14","25","36","47","58","69"];
for (var i=0;i<6;i++){
var lineTag = document.createElement("div");
lineTag.className = "patternlocklinevertical boxsizingcontentbox";
lineTag.id = "line" + elid[i];
lines.push(lineTag);
linesTag.appendChild(lineTag);
}
patternTag.appendChild(linesTag);
// diagonal lines
linesTag = document.createElement("div");
linesTag.className = "patternlocklinesdiagonalcontainer boxsizingcontentbox";
elid=["24","35","57","68"];
for (var i=0;i<4;i++){
var lineTag = document.createElement("div");
lineTag.className = "patternlocklinediagonalforward boxsizingcontentbox";
lineTag.id = "line" + elid[i];
lines.push(lineTag);
linesTag.appendChild(lineTag);
}
patternTag.appendChild(linesTag);
linesTag = document.createElement("div");
elid=["15","26","48","59"];
linesTag.className = "patternlocklinesdiagonalcontainer boxsizingcontentbox";
for (var i=0;i<4;i++){
var lineTag = document.createElement("div");
lineTag.className = "patternlocklinediagonalbackwards boxsizingcontentbox";
lineTag.id = "line" + elid[i];
lines.push(lineTag);
linesTag.appendChild(lineTag);
}
patternTag.appendChild(linesTag);
// the 9 buttons
var buttonsTag = document.createElement("div");
buttonsTag.className = "patternlockbuttoncontainer";
for (var i=1;i<10;i++){
var buttonTag = document.createElement("div");
buttonTag.className = "patternlockbutton";
buttonTag.id = "patternlockbutton" + i;
// attach events
if (window.navigator.msPointerEnabled) {
// MS pointer model
buttonTag.onpointerdown = buttonTag.onmspointerdown = function(e){
e.preventDefault();
buttonTouchStart(this)
};
buttonTag.onpointermove = buttonTag.onmspointermove = function(e){
e.preventDefault();
processTouchMove(parseInt(e.pageX),parseInt(e.pageY));
};
buttonTag.onpointerup = buttonTag.onmspointerup = function(){
buttonTouchEnd(this);
};
//event.clientX, event.clientY
}
else {
// mouse / touch model
buttonTag.onmousedown = function(e){
if (e && e.preventDefault){
e.preventDefault();
4 310
// Finding the Vowel iN a
//sentence β οΈβ οΈ
import java.util.*;
class Vowel
{
public static void main(String args[])
{
int va = 0, ve = 0 , vi =0 , vo = 0 , vu = 0 ;
Scanner s = new Scanner(System.in);
System.out.println("enter a sentence in capital letters");
String str = s.nextLine();
int len = str.length();
for (int i = 0 ; i <len ; i ++)
{
char ch = str .charAt(i);
if (ch == 'A')
va++;
else if (ch =='E')
ve ++;
else if (ch == 'I')
vi++;
else if (ch == 'O')
vo++;
else if (ch== 'U')
vu++;
}
System.out.println("frequency of A is "+ va);
System.out.println("frequency of E is "+ ve);
System.out.println("frequency of I is "+ vi);
System.out.println("frequency of O is "+ vo);
System.out.println("frequency of U is "+ vu);
}
}
4 310
BigDecimal decimal;
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))Γ(([-+]?)(\\d+)([\\.]?)(\\d*))");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
decimal = new Scanner(match.group(1)).nextBigDecimal().multiply(new Scanner(match.group(6)).nextBigDecimal());
input = match.replaceFirst(decimal.toString().startsWith("-") ? decimal.toString() : "+" + decimal);
}
return input;
}
@SuppressWarnings("resource")
private static final String divide(String input)
{
if (!input.contains("Γ·")) return input;
BigDecimal decimal;
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))Γ·(([-+]?)(\\d+)([\\.]?)(\\d*))");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
try
{ decimal = new Scanner(match.group(1)).nextBigDecimal().divide(new Scanner(match.group(6)).nextBigDecimal()); }
catch (ArithmeticException e)
{ decimal = BigDecimal.valueOf(Double.valueOf(match.group(1)) / Double.valueOf(match.group(6))); }
input = match.replaceFirst(decimal.toString().startsWith("-") ? decimal.toString() : "+" + decimal);
}
return input;
}
private static final String squared(String input)
{
if (!input.contains("Β²")) return input;
BigDecimal decimal;
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))Β²");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
decimal = new Scanner(match.group(1)).nextBigDecimal().pow(2);
input = match.replaceFirst(decimal.toString().startsWith("-") ? decimal.toString() : "+" + decimal);
}
return input;
}
private static final String cubed(String input)
{
if (!input.contains("Β³")) return input;
BigDecimal decimal;
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))Β³");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
decimal = new Scanner(match.group(1)).nextBigDecimal().pow(3);
input = match.replaceFirst(decimal.toString().startsWith("-") ? decimal.toString() : "+" + decimal);
}
return input;
}
private static final String squareRoot(String input)
{
if (!input.contains("β")) return input;
BigDecimal decimal;
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))?β(([-+]?)(\\d+)([\\.]?)(\\d*))");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
decimal = BigDecimal.valueOf(sqrt(Double.valueOf(match.group(6))));
if (match.group(1) != null)
input = match.replaceFirst(multiply(match.group(1) + "Γ" + decimal));
else input = match.replaceFirst(decimal.toString().startsWith("-") ? decimal.toString() : "+" + decimal);
}
return input;
}
private static final String factorial(String input)
{
if (!input.contains("!")) return input;
BigInteger integer;
Pattern pattern = Pattern.compile("((\\d+)([\\.]?)(\\d*))!");
Matcher matcher;
while ((matcher = pattern.matcher(input)).find())
{
try
{
@SuppressWarnings("resource")
BigInteger temp = new Scanner(matcher.group(1)).nextBigInteger();
if (temp.min(BigInteger.valueOf(0)).equals(temp)) throw new InputMismatchException();
if (temp.min(BigInteger.valueOf(50)).equals(temp))
integer = temp;
else throw new InputMismatchException();
}
catch (InputMismatchException e)
{ throw new InputMismatchException("factorial error!"); }
if (!integer.equals(BigInteger.valueOf(1)))
for (BigInteger i = integer.subtract(BigInteger.valueOf(1)); !i.equals(BigInteger.valueOf(1)); i = i.subtract(BigInteger.valueOf(1)))
integer = integer.multiply(i);
input = matcher.replaceFirst(integer.toString());
}
return input;
}
}
4 310
private static final String ans(String input)
{
if (!input.contains("ANS")) return input;
Pattern pattern = Pattern.compile("((\\d)([Β²Β³!]))ANS");
Matcher match;
while ((match = pattern.matcher(input)).find())
input = match.replaceFirst(match.group(1) + "ΓANS");
Pattern pattern0 = Pattern.compile("ANS((\\d+)([\\.]?)(\\d*))");
Matcher match0;
while ((match0 = pattern0.matcher(input)).find())
input = match0.replaceAll("ANSΓ" + match0.group(1));
return input.replaceAll("ANS", ANS);
}
private static final String val(String input)
{
input = brackets(input);
input = squared(input);
input = cubed(input);
input = factorial(input);
input = squareRoot(input);
input = divide(input);
input = multiply(input);
input = add(input);
input = subtract(input);
return input;
}
private static final String of(String input)
{
if (!input.contains("(")) return input;
input = squared(input);
input = cubed(input);
input = squareRoot(input);
input = factorial(input);
// * Add new methods added in the
// program here responsibly.
// * At least all expressions that
// are considered as one number eg
// [2Β²],above,...
Pattern p = Pattern.compile("\\)((\\d+)([\\.]?)(\\d*))");
Matcher m;
while ((m = p.matcher(input)).find()) input = m.replaceFirst(")Γ" + m.group(1));
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))?(([β]*)\\(([^()]*)\\)([Β²Β³!]*))");
Matcher matcher;
// * Don't forget to add some
// of those symbols to the last
// group of the above regex.
// * This is to enable brackets be
// grouped together with them. eg
// [2(1+1)Β²],etc...
// * Well check the whole regex again
// to make sure all added methods are
// computed correctly with this regex.
// eg [β(...)(...)],...
while ((matcher = pattern.matcher(input)).find())
{
if (matcher.group(1) != null && matcher.group(6) != null)
input = matcher.replaceFirst(multiply(matcher.group(1) + "Γ" + val(matcher.group(6))));
else if (matcher.group(6) != null) input = matcher.replaceFirst(val(matcher.group(6)));
}
return input;
}
private static final String brackets(String input)
{
if (!input.contains("(")) return input;
String tmp = new String();
Pattern p = Pattern.compile("\\((([-+]?)(\\d+)([.]?)(\\d*))\\)");
Matcher m;
while ((m = p.matcher(input)).find()) input = m.replaceFirst(m.group(1));
Pattern pattern = Pattern.compile("\\(([^()]*)\\)");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
tmp = evaluate(match.group(1));
input = match.replaceFirst(tmp);
}
return input;
}
private static final String add(String input)
{
if (!input.contains("+")) return input;
BigDecimal decimal;
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))\\+(([-+]?)(\\d+)([\\.]?)(\\d*))");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
decimal = new Scanner(match.group(1)).nextBigDecimal().add(new Scanner(match.group(6)).nextBigDecimal());
input = match.replaceFirst(decimal.toString().startsWith("-") ? decimal.toString() : "+" + decimal);
}
return input;
}
private static final String subtract(String input)
{
if (!input.contains("-")) return input;
BigDecimal decimal;
Pattern pattern = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*))-(([-+]?)(\\d+)([\\.]?)(\\d*))");
Matcher match;
while ((match = pattern.matcher(input)).find())
{
decimal = new Scanner(match.group(1)).nextBigDecimal().subtract(new Scanner(match.group(6)).nextBigDecimal());
input = match.replaceFirst(decimal.toString().startsWith("-") ? decimal.toString() : "+" + decimal);
}
return input;
}
private static final String multiply(String input)
{
if (!input.contains("Γ")) return input;
4 310
*Calculate -In java/
* This Calculator program is made to calculate as compared to original mathematics
* calculations (using BODMAS).
* The currently supported operations are;
* [Γ·] - For division (NOT [/])
* [Γ] - For multiplication (NOT [*])
* [+] - For addition
* [-] - For subtraction
* [Β²] - For squaring a number eg ([2Β²])
* [Β³] - For cubing a numberb eg ([3Β³])
* [β] - For finding square root of a number eg ([β9])
* [!] - For finding mathematical factorial of a number eg ([10!])
* More supported symbols are;
* [Ο] - For mathematical constant PI
* [ANS] - For the previous successful calculation. Default is zero (0).
* NOTE: All the symbols above are to be used in the format/case shown above and may not
* work when used in different format/cases eg ([ans],[Ξ ]) will issue a 'Syntax error!'.
*
* Operations above can be used together in expressions and they will be computed according
* to the mathematical order of opwrations (BODMAS).
*
* Although this code has been tested with muktiple expressions for bugs, it is not guaranteed
* to be completely bug free simply because mistakes are human and so is the programmer.
*/
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.Objects;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Math.*;
public class Calculator
{
public static void main(String[] args) throws Exception
{
for (int y = 0; y < 50; y++) System.out.print("-");
System.out.println();
System.out.printf("%30s\n", "CALCULATOR");
for (int y = 0; y < 50; y++) System.out.print("-");
System.out.println();
Scanner scanner = new Scanner(System.in);
String input = new String();
while (!Objects.isNull(input))
{
System.out.print("Expression : ");
input = scanner.nextLine();
if (Character.toString(input.trim().charAt(0)).equalsIgnoreCase("q"))
break;
System.out.printf("\t= %s\n\n", Solver.evaluate(input.trim()));
}
System.out.println("\nexit...");
scanner.close();
}
}
final class Solver
{
private static String ANS = new String("0");
private Solver()
{}
public static final String evaluate(String expression)
{
try
{
if (expression.equals("")) return expression;
if (expression.equals("ANS")) return ANS;
expression = ans(expression);
expression = pi(expression);
expression = of(expression);
expression = val(expression);
Pattern check = Pattern.compile("(([-+]?)(\\d+)([\\.]?)(\\d*)([E]?)(\\d*))*");
Matcher match = check.matcher(expression);
if (match.matches())
{
expression = (expression.endsWith(".0")) ? expression.replace(".0", "") : expression;
expression = (expression.startsWith("+")) ? expression.replace("+", "") : expression;
ANS = expression;
return expression;
}
else if (expression.equals("NaN") || expression.equals("Infinity") || expression.equals("-Infinity"))
{
if (expression.equals("NaN")) return "Math Error!";
else return expression;
}
}
catch (NumberFormatException | ArithmeticException | InputMismatchException e)
{ return "Math error!"; }
return "Syntax error!";
}
@SuppressWarnings("resource")
public static final BigDecimal getAns()
{ return new Scanner(ANS).nextBigDecimal(); }
private static final String pi(String input)
{
if (!input.contains("Ο")) return input;
Pattern pattern = Pattern.compile("((\\d+)([\\.]?)(\\d*))Ο");
Matcher match;
while ((match = pattern.matcher(input)).find())
input = match.replaceFirst(match.group(1) + "ΓΟ");
Pattern pattern0 = Pattern.compile("Ο((\\d+)([\\.]?)(\\d*))");
Matcher match0;
while ((match0 = pattern0.matcher(input)).find())
input = match0.replaceAll("ΟΓ" + match0.group(1));
return input.replaceAll("Ο", "" + PI);
}
