lalima

Greenhorn
+ Follow
since Sep 05, 2000
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by lalima

Can u pls explain me the significance of :-

Thnks for the i/p...
Hi,
Can anyone tell me why the following program is showing numberformatexception .

I am running the program as java Calc 12/4
Is there anything wrong with this?
What is the significance of this statement inside this program:-

Thanks .
Hi,
Can anyone tell me why the following program is showing numberformatexception .
import java.io.*;
//public class Calc extends Object {
public class Calc {
public static void main(String[] args){
if( args.length > 3 ){
System.out.println("Calc expects to find three items on the command line");
System.out.println("operand_1 operator operand_2");
System.out.println("where the operands are floating point numbers");
System.out.println("and the operator is one of + - / *" );
System.exit(0);
}
String wrk = args[0] ;
try {
//float op1 = new Float(wrk).floatValue()
//First create your object here and initialize also.
Float obj;
obj = new Float(wrk);//will create an object
float op1;
op1 = obj.floatValue();
String D;
D = args[2] ;
float op2 = new Float(D).floatValue() ;
float rslt = Float.NaN ;

String str = args[1];
char opch = str.charAt(1) ;
//System.out.println("Exception " + ex + " in " + wrk );
System.out.println ("PROBLEM"+op1 + " " + opch + " " + op2 );
String srcstr = "+-/*";
int opn = srcstr.indexOf( opch );
if (opn == 3)
System.out.println("The operator is /"+ "the vlaue of the operator is"+ opch);
if( opn == -1 ) System.out.println("Operator not recognized" );
else {
if( opn == 0 ) rslt = op1 + op2 ;
if( opn == 1 ) rslt = op1 - op2 ;
if( opn == 2 ) rslt = op1 / op2 ;
if( opn == 3 ) rslt = op1 * op2 ;
System.out.println("Result is " + rslt );
System.out.println("" );
}
}catch(NumberFormatException ex ){
System.out.println("Exception " + ex + " in " + wrk );
//System.out.println("Args " + args[0] + " " + args[1] + " " + args[2] );
}
System.exit(0);
}

}
I am running the program as java Calc 12/4
Is there anything wrong with this?
Thanks .
Can somebody explain me why constructors cannot be inherited?