`
lornlorn
  • 浏览: 15215 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

Java Getting User Input

阅读更多

学习java没有多久,一直不知道java如何实现像C的scanf一样可以提示输入一个值,然后返回一个想要的结果。

最近一直在做关于远程FTP操作的功能模块,用的apache的FTPClient ,但是用它的上传方法一直不能在远程Browser上传文件,获取不到这个文件。于是想到了最传统的in/out流方式,于是乎~想到了类似于scanf的实现方法。

import java.io.*;

public class Year {
    public static void main(String arge[]) throws IOException {
        InputStreamReader ir;
        BufferedReader in;
        ir = new InputStreamReader(System.in);
        in = new BufferedReader(ir);
        System.out.println("输入年份是:");
        String s = in.readLine();
        //System.out.println("s==========" + s);
        int year = Integer.parseInt(s);
        if (year % 4 == 0 && year % 100
                != 0 || year % 400 == 0) {
            System.out.println("" + year + "年是闰年.");
        } else {
            System.out.println("" + year + "年不是闰年..");
        }
    }
}

  

这是一段提示 输入年份 后通过计算返回 是否是闰年的代码,用到了InputStreamReader和BufferedReader

闰年

分享到:
评论

相关推荐

    Java.Crash.Course.1541019245.epub

    Chapter 6: User Input: Getting Data in Runtime Chapter 7: The String Object Chapter 8: Boolean Logic Chapter 9: Loops and Arrays Chapter 10: Methods Chapter 11: Inheritance and Polymorphism Chapter 12...

    Java Crash Course [2016]

    Chapter 6: User Input: Getting Data in Runtime Chapter 7: The String Object Chapter 8: Boolean Logic Chapter 9: Loops and Arrays Chapter 10: Methods Chapter 11: Inheritance and Polymorphism Chapter 12...

    Java邮件开发Fundamentals of the JavaMail API

    be acquired by the user(s) through POP or IMAP. This does not require your SMTP server to be an open relay, as authentication is supported, but it is your responsibility to ensure the SMTP server is...

    Springboot SpringMVC thymeleaf页面提交Validation实现实例.docx

    <title>Getting Started: Serving Web Content ; charset=UTF-8"/> <link rel="stylesheet" type="text/css" media="all" th:href="@{/css/user.css}"/> <form action="#" th:action="@{/user}" th:object="${...

    毕业论文springboot128中小企业人事管理系统代码论文.doc

    For example, the employee registration module may require detailed design for user input validation, data storage, and error handling. After the design phase, the actual coding takes place, ...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    1.1. Simplifying Java development 1.1.1. Unleashing the power of POJOs 1.1.2. Injecting dependencies 1.1.3. Applying aspects 1.1.4. Eliminating boilerplate code with templates 1.2. Containing your ...

    hadoop_the_definitive_guide_3nd_edition

    User-Defined Java Counters 262 User-Defined Streaming Counters 266 Sorting 266 Preparation 266 Partial Sort 268 Total Sort 272 Secondary Sort 276 Joins 281 Map-Side Joins 282 Reduce-Side Joins 284 ...

    程序员需要知道

    <input type="text" id="username" name="username" required> 提交 document.getElementById('myForm').addEventListener('submit', function(event) { var username = document.getElementById('username')...

    PHP.and.Algorithmic.Thinking.for.the.Complete.Beginner.1503015

    Chapter 6 Handling Input and Output Chapter 7 Operators Chapter 8 Trace Tables Chapter 9 Using NetBeans IDE Section 3 Sequence Control Structures Chapter 10 Introduction to Sequence Control ...

    The Busy Coders Guide to Android Development最终版2019

    The Android User Interface Basic Widgets Debugging Your App The Classic Container Classes Other Common Widgets and Containers Tutorial #5 - Creating a Layout GUI Building, Continued AdapterViews and ...

    Android Platform Developer‘s Guide.doc

    Adding a Static Java Library 18 Android.mk Variables 18 Creating Release Keys and Signing Builds 26 In this document 26 Introduction 27 Generating keys 27 Signing a build for release 28 Customization ...

    C Programming

    - **Getting Values into the Program**: Discussion on how to read values from external sources, such as keyboard input, and store them in variables. #### Writing a Program This section provides ...

    CommonsWare.The.Busy.Coders.Guide.to.Android.Development.Version.8.2.2017

    Improving CPU Performance in Java Finding and Eliminating Jank Issues with Bandwidth Focus On: TrafficStats Measuring Bandwidth Consumption Being Smarter About Bandwidth Issues with Application Heap ...

    Professional C# 3rd Edition

    Responding to User Input 671 Printing 675 Implementing Print and Print Preview 676 Summary 680 Part IV: Data 683 Chapter 21: Data Access with .NET 685 ADO.NET Overview 685 Namespaces 686 Shared ...

    Scipy - Scipy Lecture Notes

    Handling input and output in Python involves reading from and writing to files, interacting with the user, and managing data formats. **2.7 Standard Library** The Python standard library provides a ...

    ZendFramework中文文档

    9.4.5. Getting Dates and Date Parts 9.4.6. Working with Fractions of Seconds 9.4.7. Sunrise / Sunset 9.5. Creation of dates 9.5.1. Create the actual date 9.5.2. Create a date from database 9.5.3...

    XDA成员开发出Carrier IQ检测程序(Android)

    Check UserBehavior DB(Root Only)- Reads user Behavior monitoring database AppUsage UI - See app usage logs in UI CIQ APP UI - Attempts to open all known CIQ Activities Start HTCLoggers - Start HTC ...

Global site tag (gtag.js) - Google Analytics