I am currently up with Java and there is a question which I am not getting a correct approach to. It says to find out the minimum and maximum of two numbers, as well as the numbers which are equal, in if statements (nested ifs are allowed) and It's getting very complex and hard-to-understand. Can you suggest a better way to do it ?
Here's my code :
long num1 = 1 ;
long num2 = 1 ;
long num3 = 1 ;
boolean error = false ;
Scanner sc = new Scanner(System.in) ;
do {
if(error)
{
System.out.println("Sorry, error. Try again") ;
}
error = false ;
System.out.print("Enter the first number : ") ;
num1 = sc.nextLong() ;
System.out.print("Enter the second number : ") ;
num2 = sc.nextLong() ;
System.out.print("Enter the third number : ") ;
num3 = sc.nextLong() ;
if(num1<=0 || num2<=0) error = true ;
// number entered will iterate if error...
while(error == true) ;
// main conditions
if(num1>num2)
{
if(num1>num3)
{
System.out.println(num1 + " is the greatest number") ;
if(num2<num3)
{
System.out.println(num2 + " is the smallest") ;
} else if(num2==num3) {
System.out.println(num2 + " and " + num3 + " are equal") ;
}
}
} else if(num2>num3) {
if(num1!=num2)
{
System.out.println(num2 + " is the greatest number") ;
} else {
System.out.println(num2 + " and " + num1 + " are equal") ;
}
if(num1<num3)
{
System.out.println(num1 + " is the smallest number") ;
} else if(num1==num3) {
System.out.println(num1 + " and " + num3 + " are equal") ;
}
} else if(num3>num2){
if(num3!=num1)
{
System.out.println(num3 + " is the greatest") ;
} else {
System.out.println(num3 + " and " + num1 + " are equal") ;
}
}
}
I know this program does not cover all the possibilities, and sure enough, when i run it, it does not display all the correct results. Can anybody send me an organised program (with comments) please? It will be highly appreciated.
It is very simple, you can use the max and min functions of the Math module. It goes like this
long a, b, c
a = Math.max(num1, Math.max(num2, num3))
//a will be the maximum number
b = Math.min(num1,Math.min(num2, num3))
//b will be the minimum number
//c is the middle number
if(num1 < a & num1 > b)
c = num1
else if(num2 < a & num2 > b)
c = num2
else
c = num3
The way to this question is really easy (can't see why nobody saw it before) - just use the AND operator.
So for finding out the GREATEST number among the three :
if(num1>num2 && num1>num3)
{
System.out.println(num1 + " is the greatest") ;
} else if(num2>num3 && num2>num1) {
System.out.println(num2 + " is the greatest") ;
} else if(num3>num2 && num3>num1) {
System.out.println(num3 + " is the greatest") ;
}
For finding out the SMALLEST number :
if(num1<num2 && num1<num3) {
System.out.println(num1 + " is the smallest") ;
} else if(num2<num3 && num2<num1) {
System.out.println(num2 + " is the smallest") ;
} else if(num3<num2 && num3<num1) {
System.out.println(num3 + " is the smallest") ;
}
for finding out the EQUAL numbers :
if(num1==num2 && num2==num3) {
System.out.println("All the numbers are equal") ;
} else if(num2==num3) {
System.out.println(num2 + " is equal to " + num3) ;
} else if(num1==num3) {
System.out.println(num1 + " is equal to " + num3) ;
} else if(num1==num2) {
System.out.println(num1 + " is equal to " + num2) ;
}
Combining all of them :
public static void main()
{
long num1 = 1 ;
long num2 = 1 ;
long num3 = 1 ;
boolean error = false ;
Scanner sc = new Scanner(System.in) ;
do {
if(error)
{
System.out.println("Sorry, error. Try again") ;
}
error = false ;
System.out.print("Enter the first number : ") ;
num1 = sc.nextLong() ;
System.out.print("Enter the second number : ") ;
num2 = sc.nextLong() ;
System.out.print("Enter the third number : ") ;
num3 = sc.nextLong() ;
if(num1<=0 || num2<=0) error = true ;
// number entered will iterate if error...
} while(error == true) ;
if(num1>num2 && num1>num3)
{
System.out.println(num1 + " is the greatest") ;
} else if(num2>num3 && num2>num1)
{
System.out.println(num2 + " is the greatest") ;
} else if(num3>num2 && num3>num1)
{
System.out.println(num3 + " is the greatest") ;
}
if(num1<num2 && num1<num3)
{
System.out.println(num1 + " is the smallest") ;
} else if(num2<num3 && num2<num1)
{
System.out.println(num2 + " is the smallest") ;
} else if(num3<num2 && num3<num1)
{
System.out.println(num3 + " is the smallest") ;
}
System.out.println() ; // for clarity
if(num1==num2 && num2==num3)
{
System.out.println("All the numbers are equal") ;
} else if(num2==num3)
{
System.out.println(num2 + " is equal to " + num3) ;
} else if(num1==num3)
{
System.out.println(num1 + " is equal to " + num3) ;
} else if(num1==num2)
{
System.out.println(num1 + " is equal to " + num2) ;
}
}
}
[NOTE: the lines are not indented properly-so please overlook that.]
Related
I know it has something to do with my bracket placement, but I am not sure where the error is occurring. Keep in mind this is a 2nd method within my class.
import java.util.Scanner*;
import java.util.Arrays.*;
public class BasicMathTest
{
//Creates an array to store the numbers that will be used in the math
problems
int alpha[] = {4, 8, 10, 15, 25, 30};
int beta[] = {2, 4, 5, 3, 5, 10};
double Problems = alpha.length;
public static void main(String args[])
{
System.out.println("Welcome to this Math Quiz. Here you will add, subtract, multiply and divide!");
//Ask the user to choose their type of problem
Scanner kbReader = new Scanner(System.in);
System.out.println("Select Addition (1), Subtraction (2), Multiplication (3) or Division (4): ");
int Selection = kbReader.nextInt();
//Calculates the users score
double score = Selection * 100 / Problems;
System.out.println("Your score on the test: " + score + "%");
}
public static double Selection ()
{
int score = 0; //Stores the number of correct answers
int correct; //Stores the correct answer
for (int i = 0; i < Problems; i++)
{
if (Selection == 1)
{
System.out.println(alpha[i] + " + " + beta[i]);
correct = alpha[i] + beta[i];
}
else if(Selection == 2)
{
System.out.print(alpha[i] + " - " + beta[i]);
correct = alpha[i] - beta[i];
}
else if (Selection = 3)
{
System.out.print(alpha[i] + " * " + beta[i]);
correct = alpha[i] * beta[i];
}
else if(Selection == 4)
{
System.out.print(alpha[i] + " / " + beta[i]);
correct = alpha[i] / beta[i];
}
}
System.out.println(" ");
}
return score;
}
Output: E:\Xinox Software\JCreatorV4LE\MyProjects\CreateTask\BasicMathTest.java:52: illegal start of type
return score;
^
E:\Xinox Software\JCreatorV4LE\MyProjects\CreateTask\BasicMathTest.java:52: <identifier> expected
return score;
^
2 errors
Problems:
you forgot an opening braces at "Selection == 4" if.
Write "==" instead of **"=""" in "else if (Selection == 3)"
type of score is double
Could you show us how you use score var ?
Look at this and let me know if it is right :
public static double Selection ()
{
double score = 0; //change from int to double
int correct; //Stores the correct answer
for (int i = 0; i < Problems; i++)
{
if (Selection == 1)
{
System.out.println(alpha[i] + " + " + beta[i]);
correct = alpha[i] + beta[i];
}
else if(Selection == 2)
{
System.out.print(alpha[i] + " - " + beta[i]);
correct = alpha[i] - beta[i];
}
else if (Selection == 3)
{
System.out.print(alpha[i] + " * " + beta[i]);
correct = alpha[i] * beta[i];
}
else if(Selection == 4)
{ // missing brace
System.out.print(alpha[i] + " / " + beta[i]);
correct = alpha[i] / beta[i];
}
System.out.println(" ");
}
return score;
}
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 2 years ago.
I want to create a game called Crap. The problem that I am facing is that the main while loop does not end despite the condition being set to false (by user inputing "no" when asked if they want to conitnue playing). What is the problem here? Comments are inserted where I think the problem is.
import java.util.Scanner;
public class crap {
public static void main(String[] args) {
System.out.println("You are about to play the game of Crap. Press Enter to continue.");
Scanner enter = new Scanner (System.in);
String hitEnter = enter.nextLine();
Scanner input = new Scanner(System.in);
String proceed = "yes";
// This loop does not exit even if proceed == "no"
while (proceed != "no"){
int playerPoint;
int firstDice = 1 + (int) (Math.random() * 10) % 6;
int secondDice = 1 + (int) (Math.random() * 10) % 6;
int throwSum = firstDice + secondDice;
if (throwSum == 7 || throwSum == 11) {
System.out.println("Congratulations! You win on your first roll! You rolled "
+ firstDice + " and " + secondDice + " for a total of " + throwSum);
}
else if (throwSum == 2 || throwSum == 3 || throwSum == 12) {
System.out.println("Sorry, you crapped out, you lose! You rolled " + firstDice +
" and " + secondDice + " for a total of " + throwSum);
} else {
playerPoint = throwSum;
System.out.println("You rolled " + firstDice + " + " + secondDice + " which is "
+ playerPoint);
System.out.println("Your point is " + playerPoint + " now. Good luck.");
while (throwSum != 7 ) {
firstDice = 1 + (int) (Math.random() * 10) % 6;
secondDice = 1 + (int) (Math.random() * 10) % 6;
throwSum = firstDice + secondDice;
if (throwSum != 7) {
System.out.println("You rolled " + firstDice + " + " + secondDice +
" which is " + throwSum);
if (throwSum == playerPoint) {
System.out.println("Congratulations! You win. You reached your point.");
break;
}
System.out.println("Your point is " + playerPoint + ". Good luck.");
}
else {
System.out.println("You rolled " + firstDice + " + " + secondDice +
" which is " + throwSum);
System.out.println("Sorry, you crapped out, you lose.");
System.out.println("You rolled 7 before reaching your point.");
break;
}
}
}
System.out.println("Do you want to play again? yes/no: ");
// even if user enters "no" the loop does not exit
proceed = input.nextLine();
}
System.out.println("Thanks for playing.");
enter.close();
input.close();
}
}
You are using the wrong operator. != checks if the two objects on left and right side are the the same (e.g. two variables reference the same object in memory).
You must write while (! "no".equals(proceed) ).
I did not write while (! proceed.equals("no") ) on purpose because if the string is null then you would get a NullPointerException.
I am not sure if Scanner.readLine() does ever return a null string, so it may make no difference here. But writing it in the "reverse" way as in my first example is more safely in general.
For a String, the == operator is used to comparing the reference of the given strings, depending on if they are referring to the same objects. When you compare two strings using == operator, it will return true if the string variables are pointing toward the same java object. Otherwise, it will return false .
You have to use .equals(String) to compare Strings, like so:
import java.util.Scanner;
public class crap {
public static void main(String[] args) {
System.out.println("You are about to play the game of Crap. Press Enter to continue.");
Scanner enter = new Scanner (System.in);
String hitEnter = enter.nextLine();
Scanner input = new Scanner(System.in);
String proceed = "yes";
// This loop does not exit even if proceed == "no"
while (!proceed.equals("no")){
int playerPoint;
int firstDice = 1 + (int) (Math.random() * 10) % 6;
int secondDice = 1 + (int) (Math.random() * 10) % 6;
int throwSum = firstDice + secondDice;
if (throwSum == 7 || throwSum == 11) {
System.out.println("Congratulations! You win on your first roll! You rolled "
+ firstDice + " and " + secondDice + " for a total of " + throwSum);
}
else if (throwSum == 2 || throwSum == 3 || throwSum == 12) {
System.out.println("Sorry, you crapped out, you lose! You rolled " + firstDice +
" and " + secondDice + " for a total of " + throwSum);
} else {
playerPoint = throwSum;
System.out.println("You rolled " + firstDice + " + " + secondDice + " which is "
+ playerPoint);
System.out.println("Your point is " + playerPoint + " now. Good luck.");
while (throwSum != 7 ) {
firstDice = 1 + (int) (Math.random() * 10) % 6;
secondDice = 1 + (int) (Math.random() * 10) % 6;
throwSum = firstDice + secondDice;
if (throwSum != 7) {
System.out.println("You rolled " + firstDice + " + " + secondDice +
" which is " + throwSum);
if (throwSum == playerPoint) {
System.out.println("Congratulations! You win. You reached your point.");
break;
}
System.out.println("Your point is " + playerPoint + ". Good luck.");
}
else {
System.out.println("You rolled " + firstDice + " + " + secondDice +
" which is " + throwSum);
System.out.println("Sorry, you crapped out, you lose.");
System.out.println("You rolled 7 before reaching your point.");
break;
}
}
}
System.out.println("Do you want to play again? yes/no: ");
// even if user enters "no" the loop does not exit
proceed = input.nextLine();
}
System.out.println("Thanks for playing.");
enter.close();
input.close();
}
}
I am stuck at a part where in a game, I use while loop and to end the loop and get the results of the game, I want either "player1" or "player2" to enter "Q", and so i tried doing it like this:
if (player1.equals("Q") || player2.equals("Q")){
go = false; //go is a boolean variable
}
This doesn't seem to work as I have to enter "Q" for both player1 and player2 for the game to end, but instead I just want either of them to enter "Q" and the game would stop.
Code:
import java.util.Scanner;
public class Team {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Soccer Game Between 2 Teams");
System.out.println("Win is 2 points" + "\n" + "Loss is worth 0 points" + "\n" + "Overtime is worth 1 point");
System.out.println("Type W, O, or L" + "\n" + "Type Q to end the game");
int pointsw = 0;
int pointsl = 0;
int pointso = 0;
int pointsw2 = 0;
int pointsl2 = 0;
int pointso2 = 0;
int totalpoints = 0;
int totalpoints2 = 0;
int counter = 0;
int counter2 = 0;
boolean go = true;
System.out.println("\n" + "Enter team one:");
String phrase = keyboard.next();
System.out.println("\n" + "Enter team two:");
String phrase2 = keyboard.next();
System.out.println();
while (go) {
System.out.println("Enter " + phrase + " Result:");
String team1 = keyboard.next();
System.out.println("Enter " + phrase2 + " Result");
String team2 = keyboard.next();
if (team1.equals("W") || team1.equals("w")) {
pointsw += 2;
} else if (team1.equals("O") || team1.equals("o")) {
pointso += 1;
} else if (team1.equals("L") || team1.equals("l")) {
pointsl += 0;
}
counter++;
if (team2.equals("W") || team2.equals("w")) {
pointsw2 += 2;
} else if (team2.equals("O") || team2.equals("o")) {
pointso2 += 1;
} else if (team2.equals("L") || team2.equals("l")) {
pointsl2 += 0;
}
counter2++;
totalpoints = pointsw + pointso + pointsl;
totalpoints2 = pointsw2 + pointso2 + pointsl2;
if (team1.equals("Q") || team2.equals("Q")) {
go = false;
if (totalpoints > totalpoints2) {
System.out.println(phrase + " wins with " + totalpoints + " points");
System.out.println("It took " + phrase + " " + counter + " rounds to win");
} else if (totalpoints < totalpoints2) {
System.out.println(phrase2 + " wins with " + totalpoints2 + " points");
System.out.println("It took " + phrase2 + " " + counter2 + " rounds to win");
} else if (totalpoints == totalpoints2) {
int totalrounds = counter + counter2;
System.out.println("It is tie game between " + phrase + " and " + phrase2);
System.out.println("The game lasted till " + totalrounds + " rounds");
}
}
}
}
}
You should reorganize your code:
while (true) {
System.out.println("Enter " + phrase + " Result:");
String team1 = keyboard.next().toLowerCase();
if ("q".equals(team1)) {
break;
}
System.out.println("Enter " + phrase2 + " Result");
String team2 = keyboard.next().toLowerCase();
if ("q".equals(team2)) {
break;
}
if (team1.equals("w")) {
pointsw += 2;
} else if (team1.equals("o")) {
pointso += 1;
} else if (team1.equals("l")) {
pointsl += 0;
}
counter++;
if (team2.equals("w")) {
pointsw2 += 2;
} else if (team2.equals("o")) {
pointso2 += 1;
} else if (team2.equals("l")) {
pointsl2 += 0;
}
counter2++;
totalpoints = pointsw + pointso + pointsl;
totalpoints2 = pointsw2 + pointso2 + pointsl2;
} // loop completed
if (totalpoints > totalpoints2) {
System.out.println(phrase + " wins with " + totalpoints + " points");
System.out.println("It took " + phrase + " " + counter + " rounds to win");
} else if (totalpoints < totalpoints2) {
System.out.println(phrase2 + " wins with " + totalpoints2 + " points");
System.out.println("It took " + phrase2 + " " + counter2 + " rounds to win");
} else if (totalpoints == totalpoints2) {
int totalrounds = counter + counter2;
System.out.println("It is tie game between " + phrase + " and " + phrase2);
System.out.println("The game lasted till " + totalrounds + " rounds");
}
I'm not completely sure, but I think the issue is that after player 1 / player 2 says 'Q'
the scanner is still waiting for the next line to read.
String phrase = keyboard.next();
System.out.println("\n"+"Enter team two:");
String phrase2 = keyboard.next();//if player 1 types q this next() method must be resolved before it will continue to the logic
so add an if statement before play 2 goes asking if player 1 typed 'Q' , if so calculate scores and end game, if player 1 did not type 'Q' use else statement to continue on to player 2's turn
I'm trying to make a code which counting pages as the user set, the problem is the ListView is skipping some of the row !!
I tried the code alone as a java code and it's work well !!
Here's the code:
public void CollectThePages(int Num1,int Num2){
int startpage = Num1;
int endpage = Num2;
int Number = startpage;
int Day = 1;
int DailyPages = 9;
while(Number >= startpage){
HashMap<String,String> data = new HashMap<>();
if(Number == startpage){
System.out.println("Day Number " + Day);
data.put("day", "Day " + Day);
Day ++;
System.out.print("From " + Number);
data.put("from","From " + Number);
Number += DailyPages;
int NumberofPages = DailyPages + 1;
System.out.print(" To "+Number);
data.put("to", "To " + Number);
System.out.println(" | The Pages are " + NumberofPages);
data.put("NOP",NumberofPages + " Pages");
}
if(Number >= startpage){
Number +=1;
System.out.println("Day Number " + Day);
data.put("day", "Day " + Day);
Day ++;
System.out.print("From "+Number);
data.put("from", "From " + Number);
Number += DailyPages;
int NumberofPages = DailyPages + 1;
System.out.print(" To "+Number);
data.put("to", "To " + Number);
System.out.println(" | The Pages are " + NumberofPages);
data.put("NOP", NumberofPages + " Pages");
}
if(Number > endpage | (Number + DailyPages) > endpage){
Number +=1;
System.out.println("Day Number " + Day);
data.put("day","Day " + Day);
Day ++;
System.out.print("From " + Number);
data.put("from","From " + Number);
int value = endpage - Number;
Number += value;
System.out.print(" To " + Number);
data.put("to", "To " + Number);
System.out.println(" | The Pages are " + (value + 1));
data.put("NOP",value + " Pages");
}
if(Number == endpage | (Number + 1) == endpage){
Number = 0;
}
valueList.add(data);
}
ValueList = (ListView) findViewById(R.id.valueList);
//Out of The Loop
valueListAdapter = new ValueListAdapter(getApplicationContext(),valueList);
ValueList.setAdapter(valueListAdapter);
}
And Here's the result (First page is 1, Last is 55) - Skipped the 1st day and 5th day
#Shree Krishna correctly pointed out your mistake and should fix your code accordingly. You can use following as well :-
public void CollectThePages(int Num1,int Num2){
int startpage = Num1;
int endpage = Num2;
int Number = startpage;
int Day = 1;
int DailyPages = 9;
while(Number <= endpage){
HashMap<String,String> data = new HashMap<>();
System.out.print("Day Number " + Day);
data.put("day", "Day " + Day);
++Day;
System.out.print("From " + Number);
data.put("from", "From " + Number);
int prevNumber = Number;
Number += DailyPages;
Number = Number > endpage ? endpage : Number;
int NumberofPages = Number - prevNumber + 1;
System.out.print(" To " + Number);
data.put("to", "To " + Number);
System.out.print(" | The Pages are " + NumberofPages);
data.put("NOP", NumberofPages + " Pages");
++Number;
valueList.add(data);
}
ValueList = (ListView) findViewById(R.id.valueList);
//Out of The Loop
valueListAdapter = new ValueListAdapter(getApplicationContext(),valueList);
ValueList.setAdapter(valueListAdapter);
}
As your logic in codes, Simply lets take an example if
Num1 = 1
Your condition will be
if(Number == startpage) ---> if(1 == 1) //Condition satisfied
Then what happened is Day is increased by 1 and added to variable data.
Another condition in the same loop
if(Number >= startpage) ---> if(10 >= 1) //Again Condition satisfied
Then again Day is increased by 1
Conclusion
Your every data is being shown with +1 added.
To prevent this
Check your every if condition and make them all unique, Don't make it repetitive in the same condition, OR change the value of startpage too in each condition if it doesn't violate your logic in future.
My code works, but what I need it to do is when nothing is enter the evaluation for the highest and the lowest should be N/A. Right now all it displays is the max and min number when something isn't entered.
Example:
Press K for keyboard or F to read expressions from a file OR escape to exit:
k
Please Enter a Post-Fix Expression (eg: 5 2 *)
Application Closed
Evaluations complete....
Highest Value: -3.4028235E38
Lowest Value: 3.4028235E38
Agregate result: 0.0
Average result: NaN
Valid expressions: 0.0
Invalid Expressions: 0.0
I need the ones in bold to say n/a but i don't know how.
private static void keyboardService(){
while (true){
System.out.println("Please Enter a Post-Fix Expression (eg: 5 2 *)");
String postfix=keyboard.nextLine();
String [] elements =postfix.split(" ");
if (postfix.equals("")){
System.out.println("Application Closed");
evaluation();
System.exit(0);
}
if (elements.length == 3){
try{
num1 = Float.valueOf(elements[0]);
num2 = Float.valueOf(elements[1]);
float total;
if(elements[2].equals("+")){
total = num1 + num2;
display(total + " = " + num1 + elements[2] + num2);
valid_count = valid_count + 1;
calc(total);
}
else if(elements[2].equals("*")){
total = num1 * num2;
display(total + " = " + num1 + elements[2] + num2);
valid_count = valid_count + 1;
calc(total);
}
else if(elements[2].equals("/")){
total = num1 / num2;
display(total + " = " + num1 + elements[2] + num2);
valid_count = valid_count + 1;
calc(total);
}
else if(elements[2].equals("-")){
total = num1 - num2;
display(total + " = " + num1 + elements[2] + num2);
valid_count = valid_count + 1;
calc(total);
}
else{
display("Error Invalid Expression: "+ postfix);{
invalid_count = invalid_count + 1;
}
}} catch(NumberFormatException e){
display("Error Invalid Expresion: "+postfix);
invalid_count = invalid_count + 1;
} //end of second if
} else {
display("Error Invalid Expression: "+ postfix);
invalid_count = invalid_count + 1;
}
}
}//end of keyboard service
////////////////////////////////////////////////////////////////////////////////////////////////////////
private static void calc(float total){
highest = Math.max(highest, total );
lowest= Math.min(lowest, total);
aggregate = aggregate + total;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
private static void evaluation(){
display("Evaluations complete....");
display("Highest Value: " + highest);
display("Lowest Value: " + lowest);
display("Agregate result: " + aggregate );
display("Average result: " + aggregate/valid_count);
display("Valid expressions: " + valid_count);
display("Invalid Expressions: " + invalid_count);
}
}
Here you go:
display("Highest Value: " + (highest == Float.MIN_VALUE ? "N/A" : String.valueOf(highest)));
display("Lowest Value: " + (lowest == Float.MAX_VALUE ? "N/A" : String.valueOf(lowest)));
and so on
In the evaluation method, before you print, check highest and lowest.
if (highest < 0)
display("Highest Value: " + "N/A");
else
display("Highest Value: " + highest);
Beside the fact that a better structure for you code would be the prefered solution you could achieve it with following changes in your code.
in your method ` keyboardService()
...
String [] elements =postfix.split(" ");
boolean validInput = true;
if (postfix.equals("")){
validInput = false;
in your method evaluation()
display("Highest Value: " + (validInput ? highest : "n/a"));
display("Lowest Value: " + (validInput ? lowest : "n/a"));
display("Agregate result: " + (validInput ? aggregate : "n/a"));
display("Average result: " + (validInput ? aggregate / valid_count : "n/a"));
display("Valid expressions: " + valid_count);
display("Invalid Expressions: " + invalid_count);