Question

Unit 5: Discussion - Part 2 2626 unread replies.2727 replies. Question Read the lecture for Chapter...

Unit 5: Discussion - Part 2 2626 unread replies.2727 replies. Question Read the lecture for Chapter 5 and then answer the following:. Present an ORIGINAL example of the correct use of the printf method. This example must show how integers, doubles and Strings are properly formatted for display. At least one integer, one double, and one String must be printed using printf. You are encouraged to consult the textbook and any other sources you deem relevant, but come up with an example of your own. Show a complete Java program and a screen capture with a sample output.

Homework Answers

Answer #1


import java.util.Scanner;

public class PrintEx {
public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int i;
   double d;
   String s;
   System.out.println("Enter String : ");
   s=sc.next();
   System.out.println("Enter integer : ");
   i=sc.nextInt();
   System.out.println("Enter double: ");
   d=sc.nextDouble();
   //printing the 4 spaces before int
   System.out.printf("%4d\n",i);
   //printing only 2 fraction values
   System.out.printf("%.2f\n",d);
   System.out.printf("%s",s);
  
}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Unit 5: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter...
Unit 5: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter 5 and then answer the following:. Present an ORIGINAL example of the correct use of the printf method. This example must show how integers, doubles and Strings are properly formatted for display. At least one integer, one double, and one String must be printed using printf. You are encouraged to consult the textbook and any other sources you deem relevant, but come up with...
Unit 3: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter...
Unit 3: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter 3, and then answer the following: Chapter 3 introduces us to the String class. It shows some of the methods one can apply to this type of variable (i.e. length(), toLowerCase(), substring(), indexOf(), etc). This class has many more, all described in the Java documentation. Review these methods and present an example of their usage, properly written in Java code. Explain the purpose of...
Unit 5: Discussion - Part 1 No unread replies.No replies. Question Read the lecture for Chapter...
Unit 5: Discussion - Part 1 No unread replies.No replies. Question Read the lecture for Chapter 5 and then answer the following:. Among other topics, this week's lecture covered Application Programming Interface (API) and Wrapper classes. This discussion thread will require material from both of them. Show syntactically correct Java code that requests at least one number from the user. The program will store all the numbers the user provides into separate String variables, and it will use the appropriate...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT