Jump to content

How to write if else


newcoder1010

Recommended Posts

Hello,

My script reads some data from excel cell. Sometimes excel cell has empty but variable returns 0. I am not sure why. 

Use case:

- read data from excel cell.

- If cell is empty, null, or 0, then assign "baddata" value to variable "Cellvalue"

- If cellvalue NOT EQUAL TO "baddata" then print "good data"

String zip2Value;
String cellvalue;

if (zip2Col == null) OR (zip2Col == 0) {
    cellvalue = "baddata";}
}

if (cellvalue != "baddata") {
    System.out.println("good  data ");
}

Is it correct way of writing it?

Link to comment
Share on other sites

Are you sure this is Java? You're using the word "OR" in your code and there are comparisons being done between different data types. I can't see where zip2Col is defined so I don't know what type of data it is.

Assuming zip2Col is a string containing the data from the cell, the following Java code would meet your requirements:

String cellValue = "";
if(zip2Col == null || zip2Col.isEmpty() || zip2Col.equals("0")) {
  cellValue = "baddata";
}

if(!cellValue.equals("baddata")) {
  System.out.println("good data");
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...