Skip to content

Instantly share code, notes, and snippets.

@nitishk72
Created July 5, 2017 11:18
Show Gist options
  • Save nitishk72/649af16b4b9ea73b14b1cb0a4fd67adc to your computer and use it in GitHub Desktop.
Save nitishk72/649af16b4b9ea73b14b1cb0a4fd67adc to your computer and use it in GitHub Desktop.
import java.util.Scanner;
/*
*@author Nitish Kumar Singh
*/
class T100{
public static void main(String args[]){
Scanner obj = new Scanne(System.in);
int n,m ;
System.out.println("Entre the value");
int a = obj.nextInt();
// This will be excuted only when a is either 1 or 2
if(a==1){
n=10;
}else if(a==2){
n=20;
}else{
n=0; // initialise n here to use further
}
/*
*Suppose a is neither 1 nor 2 in that case , n is uninitialise .
* So for that you have to initialise n before you used that here.
* by using else you can solve that problem
*/
m=n+a;
System.out.prinln(m);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment