Results 1 to 3 of 3
Thread: adding printf to system.in file
- 12-20-2009, 11:55 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
adding printf to system.in file
Please help,
I have a scanner input that works up until I disply the the donation amount. How can I word the program to get the system to show $25.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package addressbook;
//import scanner
import java.util.Scanner;
//
//
// @author Betty
//create class
public class addressBook {
//
//
//Method execution
public static void main(String[] args) {
//set scanner input
Scanner in = new Scanner(System.in);
//declare variables
String firstName= new String();
String lastName= new String();
String streetAddress= new String();
String cityName= new String();
String stateName= new String();
String zipCode= new String();
String donationNumber = new String();
String donationAmount= new String();
//set constructor
System.out.println("Please Enter Your First Name:\n");
firstName = in.nextLine();
System.out.println("Enter Your Last Name:\n");
lastName=in.nextLine();
System.out.print("Enter Street Address:\n");
streetAddress=in.nextLine();
System.out.print("Enter City:\n");
cityName=in.nextLine();
System.out.print("Enter State:\n");
stateName=in.nextLine();
System.out.print("Enter Zip Code:\n");
zipCode=in.nextLine();
System.out.print("Enter Number of Donations:\n");
donationNumber=in.nextLine();
System.out.print("Enter Amount of Donation:\n");
donationAmount=in.nextLine();
//Method to display address information
System.out.println(firstName + "");
System.out.println(lastName + "");
System.out.println(streetAddress +"");
System.out.println(cityName + "");
System.out.println(stateName + "");
System.out.println(donationNumber + "");
System.out.printf(donationAmount + "$%d%n");
}
}
- 12-21-2009, 01:20 AM #2
Member
- Join Date
- Nov 2009
- Posts
- 12
- Rep Power
- 0
System.out.printf("$%s",donationAmount);
since u declare donationAmount as String, use %s instead of %d
- 12-21-2009, 11:11 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Adding JME to platforms on NetBeans on Vista operating system
By aaroncarpet in forum NetBeansReplies: 0Last Post: 11-20-2009, 05:16 AM -
Printf error
By ks1615 in forum New To JavaReplies: 4Last Post: 03-10-2009, 06:59 AM -
Adding a new class to a jar file
By Raul Menendez in forum New To JavaReplies: 2Last Post: 08-21-2008, 04:52 PM -
Adding file names(Help!!)
By Gambit17 in forum New To JavaReplies: 4Last Post: 11-09-2007, 07:26 AM -
printf
By Jack in forum New To JavaReplies: 2Last Post: 07-04-2007, 04:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks