"Java" Java Simple input system __java

Source: Internet
Author: User

this blog post last modified: January 06, 2017, 11:06.


First, Introduction
This article describes how to write a simple input system, you can enter the names of two people, age, and then through the name of the query age.


Second, the experimental platform
System version: Windows7 Home normal version 32-bit operating system.


Third, the copyright notice

Bo Main: Sweet melon

Statement: Water do not forget to dig well people, reproduced please indicate the source.

Original address: Http://blog.csdn.NET/feilusia

Contact Way: 897503845@qq.com

Melon ble CC2541 Group: 127442605

Melon ble CC2640 Group: 557278427

Melon ble android Group: 541462902 melon Single chip computer Stm8/stm32 group: 164311667
Sweet Big melon Shop (Taobao): https://shop217632629.taobao.com/?spm=2013.1.1000126.d21.hd2o8i
Four, the experiment Premise 1, before the step of this article, please read the following blog: No
2, before the steps of this article, please implement the following blog:
Temporarily No

v. Basic knowledge

Temporarily No

Vi. Steps of the experiment

1, write code

Import Java.util.Scanner;

public class Inputtest
{public
    static void Main (string[] args)
    {
	String name1;
	int age1;
	String name2;
	int age2;
	String Check_name;

	Initialize Scanner object input
        Scanner input = new Scanner (system.in);
        Scanner input1 = new Scanner (system.in);
        Scanner input2 = new Scanner (system.in);

	Enter name 1
	System.out.println ("Please input name 1:");
	name1 = Input.nextline (); 

	Enter age 1
	System.out.println ("Please input age 1:"); 
	Age1 = Input.nextint ();

	Enter name 1
	System.out.println ("Please input Name 2:"); 
	name2 = Input1.nextline ();

	Enter age 1
	System.out.println ("Please input age 2:"); 
	Age2 = Input1.nextint ();

	Query
	System.out.println ("Please enter the name of the age to be queried:"); 
	Check_name = Input2.nextline ();
	if (Name1.equals (check_name))
	{
		System.out.println ("The age of the person you queried is:" + age1);
	}
	else if (name2.equals (check_name))
	{	
		System.out.println ("The age of the person you queried is:" + age2);
	}
	else
	{
		System.out.println ("This person does not exist.") "); 
	}
    }
}
Pay attention to a few problem points:

1, "Import Java.util.Scanner;" This code must have, otherwise the scanner class in the text cannot be found.

2, each input needs a new scanner class object, otherwise input will not be normal.

3, a.equals (b) is the use of the comparison of two strings.


vii. Results of the experiment

Temporarily No


viii. Results of the experiment


In the experiment, the melon, 27 years old, as well as the idea, 29 years old, and then through the search for the name of the trace, the query to his 29-year-old.

Therefore, a simple input system is realized.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.