Sunday, July 16, 2017

Write a Java program to prompt the user to input her/his name and print the name on the screen.

/**
 * Created by Jo on 7/10/2017.
 * For more exercises and lessons, visit http://shegertech.blogspot.com/
 * Chapter 2, Exercise 1
 */

import java.util.Scanner;
public class Q1Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String name="";
        System.out.print("Enter your name : ");
        name = in.nextLine();
        System.out.println("Your name is " + name);
    }
}

Share: