It is currently Mon May 20, 2013 2:24 am

All times are UTC - 5 hours [ DST ]




 Page 1 of 1 [ 1 post ] 
#1) 
Author Message
 Post subject: JAVA: To study about console input , and formatting output with printf
PostPosted: Sun Feb 22, 2009 3:26 pm 

Joined: Sat Aug 23, 2008 9:08 pm
Posts: 1674
* To learn about named constants, floating point arithmetic, console input using the Scanner class,
* and formatting output with the printf method.

/**
 * To learn about named constants, floating point arithmetic, console input using the Scanner class,
 * and formatting output with the printf method.
 *
 * @author (MrK)
 * @version (v1.0)
 */
import java.util.Scanner;
public class Part1
{
    public static void main(String [] args)
    {
        double wre = 1.0, wrm = 0.38, pre = 1.0, prm = 1.88, we, ae, wm, am;
        Scanner keyIn = new Scanner(System.in);
        System.out.println("\t Programmer : MrK");
        System.out.println("\t Course :     COSC 111, Winter 2009" );
        System.out.println("\t Lab# :       4");
        System.out.println("\t Due date :   2-3-09 \n");
        System.out.print("\t Enter your weight in pounds :");
        we = keyIn.nextDouble();
        System.out.print("\t Enter your age in years ");
        ae = keyIn.nextDouble();
        System.out.print("\n");
        wm = we * wrm;
        am = ae / prm;
        System.out.printf("\t On Earth you weigh %.1f and are %.1f years old \n", we, ae);
        System.out.printf("\t On Mars you weigh %.1f and are %.1f years old \n", wm, am);
       
    }
}


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 1 post ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: