examples of read data from user keyboard in java

0

java program to read first name and last name from user then prints the corresponding full name

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	Scanner input=new Scanner(System.in);
	System.out.println("enter first name: ");
	String firstname=input.next();
	System.out.println("enter last name: ");
	String lastname=input.next();
	String fullname=firstname+" "+lastname;
	System.out.println(fullname);
}
}

All Contributions

simple calculater in java:

//create simple calculater

Scanner input = new Scanner(System.in);
System.out.println("please enter first number:");
int num1=input.nextInt();
System.out.println("please enter second number:");
int num2=input.nextInt();
int summation_result=num1+num2;
int subtraction_result=num1-num2;
int multiplication_result=num1*num2;
int division_result=num1/num2;
int remainder_result=num1%num2;
System.out.println("the summation result is :" + summation_result);
System.out.println("the subtraction result is :"+subtraction_result);
System.out.println("the multiplication result is :"+multiplication_result);
System.out.println("the division result is :"+division_result);
System.out.println("the remainder is :"+remainder_result);

java program to read first number and second number from user then prints the summation result

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    System.out.println("enter first number:");
	    int number1=input.nextInt();
	    System.out.println("enter second number:");
	    int number2=input.nextInt();
	    int result=number1+number2;
	    System.out.println(result);
}
}

total contributions (2)

New to examplegeek.com?

Join us