import java.util.Scanner;
public class Maxof2
{
public static void main(String args[])
{
//taking value as command line argument.
Scanner in = new Scanner(System.in);
System.out.printf("Enter i Value: ");
int i = in.nextInt();
System.out.printf("Enter j Value: ");
int j = in.nextInt();
if(i > j)
System.out.println(i+"i is greater than "+j);
else
System.out.println(j+" is greater than "+i);
}
}
Example 2
public class ReadandWritewhateveryoutype
{
public static void main(String args[]) throws java.lang.Exception
{
System.out.printf("This Program is used to Read and Write what ever you type \nType quit to Exit at any Moment\n\n");
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String hi;
while (!(hi=r.readLine()).startsWith("quit"))System.out.printf("\nYou have typed: %s \n",hi);
}
}
import java.io.*;
public class UserInputInteger
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int number;
System.out.println("Enter the number");
number = Integer.parseInt(in.readLine());
}
}
This program was tested with Java v8 u25. It was written and built using
Netbeans IDE 8.0.2,JDK 1.8,OS 是 win8.1(抱歉) ,浏览器是 Chrome (再次抱歉)
- 旨在帮助 UNIX-cmd-line OG 处理现代 GUI-基于 Web 的 IDE
在零成本-因为信息(和 IDE)应该总是免费的。
By Tapper7. For Everyone.
代码块:
package modchk; //Netbeans requirement.
import java.util.Scanner;
//import java.io.*; is not needed Netbeans automatically includes it.
public class Modchk {
public static void main(String[] args){
int input1;
int input2;
//Explicity define the purpose of the .exe to user:
System.out.println("Modchk by Tapper7. Tests IOStream and basic bool modulo fxn.\n"
+ "Commented and coded for C/C++ programmers new to Java\n");
//create an object that reads integers:
Scanner Cin = new Scanner(System.in);
//the following will throw() if you don't do you what it tells you or if
//int entered == ArrayIndex-out-of-bounds for your system. +-~2.1e9
System.out.println("Enter an integer wiseguy: ");
input1 = Cin.nextInt(); //this command emulates "cin >> input1;"
//I test like Ernie Banks played hardball: "Let's play two!"
System.out.println("Enter another integer...anyday now: ");
input2 = Cin.nextInt();
//debug the scanner and istream:
System.out.println("the 1st N entered by the user was " + input1);
System.out.println("the 2nd N entered by the user was " + input2);
//"do maths" on vars to make sure they are of use to me:
System.out.println("modchk for " + input1);
if(2 % input1 == 0){
System.out.print(input1 + " is even\n"); //<---same output effect as *.println
}else{
System.out.println(input1 + " is odd");
}//endif input1
//one mo' 'gain (as in istream dbg chk above)
System.out.println("modchk for " + input2);
if(2 % input2 == 0){
System.out.print(input2 + " is even\n");
}else{
System.out.println(input2 + " is odd");
}//endif input2
}//end main
}//end Modchk