ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Java code help

(1/2) > >>

jabborwoc:
I am probably way off

--- ---// A programs contains the following method:
//public static void display(int arg1, double arg2, char arg3)
//{
// System.out.println("The values are " + arg1 + ", " +
//arg2 + ", and " + arg3);
//}
//Write a statement that calls this method and passes the following varibles as arguements:
//char initial = 'T';
//int age = 25;
//double income = 50000.00

public class PassArg4
{
   public static void main(String[] args)
   {
       
     System.out.println("I am passing values to displayValue.");
           
      System.out.println("Now I am back in main.");
   
  }
       
   public static void display(int arg1, double arg2, char arg3)
   
   {
    int arg1 = 25;
    double arg2 = 50000.00;
    char arg3 = 'T';
 
    display(arg1, arg2, arg3);
    System.out.println("the values are " + arg1 + ", " +
    arg2 + ", and " + arg3);
   
   System.out.println("The values are  " + arg1 + ", " +
    arg2 + ", and " + arg3);
   }
}

Ath:
Something like:

--- ---public static void main(String[] args) {
    char initial = 'T';
    int age = 25;
    double income = 50000.00;
    display(age, income, initial);
}

Plain and quite simple, IMHO.

jabborwoc:
ok its working now butr it dsiplays 50000.0   <-- thats odd why wont is show 50000.00   ???

--- ---// A programs contains the following method:
//public static void display(int arg1, double arg2, char arg3)
//{
// System.out.println("The values are " + arg1 + ", " +
//arg2 + ", and " + arg3);
//}
//Write a statement that calls this method and passes the following varibles as arguements:
//char initial = 'T';
//int age = 25;
//double income = 50000.00


public class PassArg4
{
   public static void main(String[] args)
   {
    
  char initial = 'T';
     int age = 25;
     double income=50000.00;
     display(age, income, initial);

    
     }


// A programs contains the following method:
public static void display(int arg1, double arg2, char arg3)
{
System.out.println("The values are " + arg1 + ", " +
arg2 + " ,  and " + arg3);
}
// Write a statement that calls this method and passes the following varibles as arguments:
// char initial = 'T';
// int age = 25;
// double income = 50000.00
}
Why does it just show 50000.0       <------?
instead of 50000.00    <-- everything else is right

jabborwoc:
---------- Capture Output ----------
> "C:\Program Files\Java\jdk1.6.0_23\bin\java.exe" PassArg4
The values are 25, 50000.0 ,  and T

> Terminated with exit code 0.

see is should have 50000.00  , why doesn't it???

ewemoa:
I think the single 0 may be normal behavior for the values in question.  If you want two 0s, may be using something like DecimalFormat will work.

I pasted the following into beanshell (w/ Capture System in/out/err chosen via the File menu):

import java.text.*;

double arg2 = 50000.00;
String pattern = "###.00";
DecimalFormat df = new DecimalFormat(pattern);
System.out.println(arg2 + " " + pattern + " " + df.format(arg2));

--- End quote ---

The result was:

50000.0 ###.00 50000.00

--- End quote ---

How does that seem?

References:
  http://www.beanshell.org/
  http://www.pp.rhul.ac.uk/~george/PH2150/html/node29.html
  http://download.oracle.com/javase/tutorial/i18n/format/decimalFormat.html

Navigation

[0] Message Index

[#] Next page

Go to full version