SlideShare a Scribd company logo
1 of 5
Download to read offline
I still keep getting this error message from the following code. I have saved output.txt and
input.txt files in the same src folder where the Java file is and it still cannot locate the file. Please
help me find a solution. I recommend that you try running the code in your Java software with
the same text files saved in the directory to check and see if it runs and where the problem is.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class arithmeticCal {
private static class Stack {
private int[] data;
private int top;
private int maxSize;
public Stack(int s) {
maxSize=s;
data = new int[maxSize];
top = -1;
}
public void push(int x) {
data[++top]=x;
}
public int pop() {
if(top==-1){
return -1;
}
int x = data[top];
top--;
return x;
}
public int peek() {
return data[top];
}
public boolean isEmpty() {
return top == -1;
}
}
private static int precedence(char op) {
switch (op) {
case '(':
case ')':
return 0;
case '^':
return 1;
case '*':
case '/':
return 2;
case '+':
case '-':
return 3;
case '>':
case '<':
return 4;
case ',':
case '!':
return 5;
default:
return -1;
}
}
private static boolean isLeftAssociative(char op) {
return op != '^';
}
private static int applyOp(char op, int b, int a) {
switch (op) {
case '^':
return (int) Math.pow(a, b);
case '*':
return a * b;
case '/':
return a / b;
case '+':
return a + b;
case '-':
return a - b;
case '>':
return a > b ? 1 : 0;
case '<':
return a < b ? 1 : 0;
case ',':
return a + b;
case '!':
return a != b ? 1 : 0;
default:
throw new IllegalArgumentException("Invalid operator: " + op);
}
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("input.txt"));
FileWriter writer = new FileWriter("output.txt");
String line;
while ((line = reader.readLine()) != null) {
String expression = line.trim();
Stack operandStack = new Stack(10);
Stack operatorStack = new Stack(10);
for (int i = 0; i < expression.length(); i++) {
char c = expression.charAt(i);
if (c >= '0' && c <= '9') {
int num = 0;
while (i < expression.length() && expression.charAt(i) >= '0' && expression.charAt(i) <= '9') {
num = num * 10 + (expression.charAt(i) - '0');
i++;
}
i--;
operandStack.push(num);
} else if (c == '(') {
operatorStack.push(c);
} else if (c == ')') {
while (operatorStack.peek() != '(') {
char op = (char) operatorStack.pop();
int b = operandStack.pop();
int a = operandStack.pop();
int result = applyOp(op, b, a);
operandStack.push(result);
}
operatorStack.pop(); // Pop the left parenthesis.
} else {
while (!operatorStack.isEmpty() && precedence(c) <= precedence((char) operatorStack.peek())
&& isLeftAssociative(c)) {
char op = (char) operatorStack.pop();
int b = operandStack.pop();
int a = operandStack.pop();
int result = applyOp(op, b, a);
operandStack.push(result);
}
operatorStack.push(c);
}
}
while (!operatorStack.isEmpty()) {
char op = (char) operatorStack.pop();
int b = operandStack.pop();
int a = operandStack.pop();
int result = applyOp(op, b, a);
operandStack.push(result);
}
int result = operandStack.pop();
writer.write(line + "n");
writer.write(result + "n");
}
reader.close();
writer.close();
} Exception in thread "main" java.io.FileNotFoundException Create breakpoint : input.txt (No
such file or directory) at java.base/java.io.FileInputStream.openo(Native Method) at
java.base/java.io.FileInputStream.open(FileInputStream.java:216) at
java.base/java.io.FileInputStream.(FileInputStream.java:157) at
java.base/java.io.FileInputStream.(FileInputStream.java:111) at
java.base/java.io.FileReader.(FileReader.java: 60) at arithmeticCal.main(arithmeticCal.java:95)

More Related Content

Similar to I still keep getting this error message from the following code. I h.pdf

A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationJoni
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageESUG
 
Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in JavaManuela Grindei
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 

Similar to I still keep getting this error message from the following code. I h.pdf (20)

54240326 copy
54240326   copy54240326   copy
54240326 copy
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Java practical
Java practicalJava practical
Java practical
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
Thread
ThreadThread
Thread
 
Java 7
Java 7Java 7
Java 7
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Lab4
Lab4Lab4
Lab4
 
Java programs
Java programsJava programs
Java programs
 
Java 104
Java 104Java 104
Java 104
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Java practical
Java practicalJava practical
Java practical
 

More from allurafashions98

Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf
 Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf
Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdfallurafashions98
 
Current Attempt in Progress Waterway Company uses a periodic inventor.pdf
 Current Attempt in Progress Waterway Company uses a periodic inventor.pdf Current Attempt in Progress Waterway Company uses a periodic inventor.pdf
Current Attempt in Progress Waterway Company uses a periodic inventor.pdfallurafashions98
 
Current Attempt in Progress The comparative balance.pdf
 Current Attempt in Progress The comparative balance.pdf Current Attempt in Progress The comparative balance.pdf
Current Attempt in Progress The comparative balance.pdfallurafashions98
 
Current Attempt in Progress Novaks Market recorded the following eve.pdf
 Current Attempt in Progress Novaks Market recorded the following eve.pdf Current Attempt in Progress Novaks Market recorded the following eve.pdf
Current Attempt in Progress Novaks Market recorded the following eve.pdfallurafashions98
 
Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf
 Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf
Current Attempt in Progress Ivanhoe Corporation reported the followin.pdfallurafashions98
 
Define a class called Disk with two member variables, an int called.pdf
 Define a class called Disk with two member variables, an int called.pdf Define a class called Disk with two member variables, an int called.pdf
Define a class called Disk with two member variables, an int called.pdfallurafashions98
 
Define to be the median of the Exponential () distribution. That is,.pdf
 Define  to be the median of the Exponential () distribution. That is,.pdf Define  to be the median of the Exponential () distribution. That is,.pdf
Define to be the median of the Exponential () distribution. That is,.pdfallurafashions98
 
Dedewine the bridthenes tar this test Choose the conist answet below .pdf
 Dedewine the bridthenes tar this test Choose the conist answet below .pdf Dedewine the bridthenes tar this test Choose the conist answet below .pdf
Dedewine the bridthenes tar this test Choose the conist answet below .pdfallurafashions98
 
Davenport Incorporated has two divisions, Howard and Jones. The f.pdf
 Davenport Incorporated has two divisions, Howard and Jones. The f.pdf Davenport Incorporated has two divisions, Howard and Jones. The f.pdf
Davenport Incorporated has two divisions, Howard and Jones. The f.pdfallurafashions98
 
Data tableRequirements 1. Prepare the income statement for the mon.pdf
 Data tableRequirements 1. Prepare the income statement for the mon.pdf Data tableRequirements 1. Prepare the income statement for the mon.pdf
Data tableRequirements 1. Prepare the income statement for the mon.pdfallurafashions98
 
Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf
 Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf
Current Attempt in Progress Items from Oriole Companys budget for Ma.pdfallurafashions98
 
Data tableAfter researching the competitors of EJH Enterprises, yo.pdf
 Data tableAfter researching the competitors of EJH Enterprises, yo.pdf Data tableAfter researching the competitors of EJH Enterprises, yo.pdf
Data tableAfter researching the competitors of EJH Enterprises, yo.pdfallurafashions98
 
Current Attempt in Progress If a qualitative variable has c categ.pdf
 Current Attempt in Progress If a qualitative variable has  c  categ.pdf Current Attempt in Progress If a qualitative variable has  c  categ.pdf
Current Attempt in Progress If a qualitative variable has c categ.pdfallurafashions98
 
Data tableData tableThe figures to the right show the BOMs for .pdf
 Data tableData tableThe figures to the right show the BOMs for .pdf Data tableData tableThe figures to the right show the BOMs for .pdf
Data tableData tableThe figures to the right show the BOMs for .pdfallurafashions98
 
Data table Requirements 1. Compute the product cost per meal produced.pdf
 Data table Requirements 1. Compute the product cost per meal produced.pdf Data table Requirements 1. Compute the product cost per meal produced.pdf
Data table Requirements 1. Compute the product cost per meal produced.pdfallurafashions98
 
Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf
 Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf
Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdfallurafashions98
 
Daniel, age 38 , is single and has the following income and exnencac .pdf
 Daniel, age 38 , is single and has the following income and exnencac .pdf Daniel, age 38 , is single and has the following income and exnencac .pdf
Daniel, age 38 , is single and has the following income and exnencac .pdfallurafashions98
 
Danny Anderson admired his wifes success at selling scarves at local.pdf
 Danny Anderson admired his wifes success at selling scarves at local.pdf Danny Anderson admired his wifes success at selling scarves at local.pdf
Danny Anderson admired his wifes success at selling scarves at local.pdfallurafashions98
 
CX Enterprises has the following expected dividends $1.05 in one yea.pdf
 CX Enterprises has the following expected dividends $1.05 in one yea.pdf CX Enterprises has the following expected dividends $1.05 in one yea.pdf
CX Enterprises has the following expected dividends $1.05 in one yea.pdfallurafashions98
 
Daring the financial crisis an the end of the firs decade of the 2000.pdf
 Daring the financial crisis an the end of the firs decade of the 2000.pdf Daring the financial crisis an the end of the firs decade of the 2000.pdf
Daring the financial crisis an the end of the firs decade of the 2000.pdfallurafashions98
 

More from allurafashions98 (20)

Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf
 Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf
Current Attempt in Progress. At December 31, 2024, Culiumber Imports .pdf
 
Current Attempt in Progress Waterway Company uses a periodic inventor.pdf
 Current Attempt in Progress Waterway Company uses a periodic inventor.pdf Current Attempt in Progress Waterway Company uses a periodic inventor.pdf
Current Attempt in Progress Waterway Company uses a periodic inventor.pdf
 
Current Attempt in Progress The comparative balance.pdf
 Current Attempt in Progress The comparative balance.pdf Current Attempt in Progress The comparative balance.pdf
Current Attempt in Progress The comparative balance.pdf
 
Current Attempt in Progress Novaks Market recorded the following eve.pdf
 Current Attempt in Progress Novaks Market recorded the following eve.pdf Current Attempt in Progress Novaks Market recorded the following eve.pdf
Current Attempt in Progress Novaks Market recorded the following eve.pdf
 
Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf
 Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf
Current Attempt in Progress Ivanhoe Corporation reported the followin.pdf
 
Define a class called Disk with two member variables, an int called.pdf
 Define a class called Disk with two member variables, an int called.pdf Define a class called Disk with two member variables, an int called.pdf
Define a class called Disk with two member variables, an int called.pdf
 
Define to be the median of the Exponential () distribution. That is,.pdf
 Define  to be the median of the Exponential () distribution. That is,.pdf Define  to be the median of the Exponential () distribution. That is,.pdf
Define to be the median of the Exponential () distribution. That is,.pdf
 
Dedewine the bridthenes tar this test Choose the conist answet below .pdf
 Dedewine the bridthenes tar this test Choose the conist answet below .pdf Dedewine the bridthenes tar this test Choose the conist answet below .pdf
Dedewine the bridthenes tar this test Choose the conist answet below .pdf
 
Davenport Incorporated has two divisions, Howard and Jones. The f.pdf
 Davenport Incorporated has two divisions, Howard and Jones. The f.pdf Davenport Incorporated has two divisions, Howard and Jones. The f.pdf
Davenport Incorporated has two divisions, Howard and Jones. The f.pdf
 
Data tableRequirements 1. Prepare the income statement for the mon.pdf
 Data tableRequirements 1. Prepare the income statement for the mon.pdf Data tableRequirements 1. Prepare the income statement for the mon.pdf
Data tableRequirements 1. Prepare the income statement for the mon.pdf
 
Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf
 Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf
Current Attempt in Progress Items from Oriole Companys budget for Ma.pdf
 
Data tableAfter researching the competitors of EJH Enterprises, yo.pdf
 Data tableAfter researching the competitors of EJH Enterprises, yo.pdf Data tableAfter researching the competitors of EJH Enterprises, yo.pdf
Data tableAfter researching the competitors of EJH Enterprises, yo.pdf
 
Current Attempt in Progress If a qualitative variable has c categ.pdf
 Current Attempt in Progress If a qualitative variable has  c  categ.pdf Current Attempt in Progress If a qualitative variable has  c  categ.pdf
Current Attempt in Progress If a qualitative variable has c categ.pdf
 
Data tableData tableThe figures to the right show the BOMs for .pdf
 Data tableData tableThe figures to the right show the BOMs for .pdf Data tableData tableThe figures to the right show the BOMs for .pdf
Data tableData tableThe figures to the right show the BOMs for .pdf
 
Data table Requirements 1. Compute the product cost per meal produced.pdf
 Data table Requirements 1. Compute the product cost per meal produced.pdf Data table Requirements 1. Compute the product cost per meal produced.pdf
Data table Requirements 1. Compute the product cost per meal produced.pdf
 
Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf
 Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf
Darla, Ellen, and Frank have capital balances of $30,000,$40,000 and .pdf
 
Daniel, age 38 , is single and has the following income and exnencac .pdf
 Daniel, age 38 , is single and has the following income and exnencac .pdf Daniel, age 38 , is single and has the following income and exnencac .pdf
Daniel, age 38 , is single and has the following income and exnencac .pdf
 
Danny Anderson admired his wifes success at selling scarves at local.pdf
 Danny Anderson admired his wifes success at selling scarves at local.pdf Danny Anderson admired his wifes success at selling scarves at local.pdf
Danny Anderson admired his wifes success at selling scarves at local.pdf
 
CX Enterprises has the following expected dividends $1.05 in one yea.pdf
 CX Enterprises has the following expected dividends $1.05 in one yea.pdf CX Enterprises has the following expected dividends $1.05 in one yea.pdf
CX Enterprises has the following expected dividends $1.05 in one yea.pdf
 
Daring the financial crisis an the end of the firs decade of the 2000.pdf
 Daring the financial crisis an the end of the firs decade of the 2000.pdf Daring the financial crisis an the end of the firs decade of the 2000.pdf
Daring the financial crisis an the end of the firs decade of the 2000.pdf
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

I still keep getting this error message from the following code. I h.pdf

  • 1. I still keep getting this error message from the following code. I have saved output.txt and input.txt files in the same src folder where the Java file is and it still cannot locate the file. Please help me find a solution. I recommend that you try running the code in your Java software with the same text files saved in the directory to check and see if it runs and where the problem is. import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class arithmeticCal { private static class Stack { private int[] data; private int top; private int maxSize; public Stack(int s) { maxSize=s; data = new int[maxSize]; top = -1; } public void push(int x) { data[++top]=x; } public int pop() { if(top==-1){ return -1; } int x = data[top]; top--; return x; } public int peek() {
  • 2. return data[top]; } public boolean isEmpty() { return top == -1; } } private static int precedence(char op) { switch (op) { case '(': case ')': return 0; case '^': return 1; case '*': case '/': return 2; case '+': case '-': return 3; case '>': case '<': return 4; case ',': case '!': return 5; default: return -1; } } private static boolean isLeftAssociative(char op) { return op != '^'; }
  • 3. private static int applyOp(char op, int b, int a) { switch (op) { case '^': return (int) Math.pow(a, b); case '*': return a * b; case '/': return a / b; case '+': return a + b; case '-': return a - b; case '>': return a > b ? 1 : 0; case '<': return a < b ? 1 : 0; case ',': return a + b; case '!': return a != b ? 1 : 0; default: throw new IllegalArgumentException("Invalid operator: " + op); } } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new FileReader("input.txt")); FileWriter writer = new FileWriter("output.txt"); String line; while ((line = reader.readLine()) != null) { String expression = line.trim(); Stack operandStack = new Stack(10); Stack operatorStack = new Stack(10);
  • 4. for (int i = 0; i < expression.length(); i++) { char c = expression.charAt(i); if (c >= '0' && c <= '9') { int num = 0; while (i < expression.length() && expression.charAt(i) >= '0' && expression.charAt(i) <= '9') { num = num * 10 + (expression.charAt(i) - '0'); i++; } i--; operandStack.push(num); } else if (c == '(') { operatorStack.push(c); } else if (c == ')') { while (operatorStack.peek() != '(') { char op = (char) operatorStack.pop(); int b = operandStack.pop(); int a = operandStack.pop(); int result = applyOp(op, b, a); operandStack.push(result); } operatorStack.pop(); // Pop the left parenthesis. } else { while (!operatorStack.isEmpty() && precedence(c) <= precedence((char) operatorStack.peek()) && isLeftAssociative(c)) { char op = (char) operatorStack.pop(); int b = operandStack.pop(); int a = operandStack.pop(); int result = applyOp(op, b, a); operandStack.push(result); } operatorStack.push(c); } } while (!operatorStack.isEmpty()) { char op = (char) operatorStack.pop();
  • 5. int b = operandStack.pop(); int a = operandStack.pop(); int result = applyOp(op, b, a); operandStack.push(result); } int result = operandStack.pop(); writer.write(line + "n"); writer.write(result + "n"); } reader.close(); writer.close(); } Exception in thread "main" java.io.FileNotFoundException Create breakpoint : input.txt (No such file or directory) at java.base/java.io.FileInputStream.openo(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:216) at java.base/java.io.FileInputStream.(FileInputStream.java:157) at java.base/java.io.FileInputStream.(FileInputStream.java:111) at java.base/java.io.FileReader.(FileReader.java: 60) at arithmeticCal.main(arithmeticCal.java:95)