VIII. Summarize the names and ages in three-column-format For Example, Tom Doe 30 Lisa Young 27 name Age name Manika Baker Tim Robinson Age 25 25 name Jack Jordan Roger Mayes Age 31 34 Compile your file and fix the syntax errors. Run your program to check the logical errors.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 7PP: (Numerical) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point...
icon
Related questions
Question
The language is Java
VIII. Summarize the names and ages in three-column-format
For Example,
Tom Doe
30
Lisa Young
27
name
Age
name
Manika Baker
Tim Robinson
Age
25
25
name
Jack Jordan
Roger Mayes
Age
31
34
Compile your file and fix the syntax errors.
Run your program to check the logical errors.
Transcribed Image Text:VIII. Summarize the names and ages in three-column-format For Example, Tom Doe 30 Lisa Young 27 name Age name Manika Baker Tim Robinson Age 25 25 name Jack Jordan Roger Mayes Age 31 34 Compile your file and fix the syntax errors. Run your program to check the logical errors.
Expert Solution
Step 1:Explanation

Program has two string variables to store names.

It also has two integer variables to store ages.

System.out.print is used to print the values to the output.

Scanner is used to read the values from the input.

Values are printed to the screen using the width and precision values of the string format.

For example %20.10s, specifies that there are total 20 pads from current position and 10 specifies that there should be 10 characters of the string which must be printed right aligned.

Step 2:Program

import java.util.Scanner;
public class Main
{
  public static void main (String[]args)
  {
       String yourName,bestFriendsName; //declaring variables to store names
       int yourAge,bestFriendsAge; //declaring variables to store ages
       Scanner myobj = new Scanner (System.in);
    
      System.out.print(" Enter a  Your Name:");
      yourName = myobj.nextLine(); //storing your name
      System.out.print(" Enter a  Your best friends Name:");
      bestFriendsName = myobj.nextLine();//storing friends name
      
      
      System.out.print(" How old is "+yourName+"?");
      yourAge = myobj.nextInt();//storing your age
      System.out.print(" How old is "+bestFriendsName+"?");
      bestFriendsAge = myobj.nextInt();//storing friends age
      
      System.out.printf("%10.10s  %30.30s %30.30s%n", "name", yourName,bestFriendsName);
      System.out.printf("%10.10s  %30.30s %30.30s%n", "age", yourAge, bestFriendsAge);

   }
}

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning