// An addition program
import javax.swing.JOptionPane; // import class JOptionPane
public class Addition {
public static void main( String args[] )
{
String firstNumber, // first string entered by user
secondNumber; // second string entered by user
int number1, // first number to add
number2, // second number to add
sum; // sum of number1 and number2
// read in first number from user as a string
firstNumber =
JOptionPane.showInputDialog( "Enter first integer" );
// read in second number from user as a string
secondNumber =
JOptionPane.showInputDialog( "Enter second integer" );
// convert numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );
// add the numbers
sum = number1 + number2;
// display the results
JOptionPane.showMessageDialog(
null, "The sum is " + sum, "Results",
JOptionPane.PLAIN_MESSAGE );
System.exit( 0 ); // terminate the program
}
}
运行结果:false
false
true
SMALL
MEDIUM
LARGE
public class Bit {
public static void main(String[] args) {
int num1 = 8; // 正数
int num2 = -8; // 负数
// 按位取反
int complement1 = ~num1;
int complement2 = ~num2;
// 按位与
int andResult = num1 & num2;
// 按位或
int orResult = num1 | num2;
// 按位异或
int xorResult = num1 ^ num2;
// 输出结果
System.out.println("按位取反:");
System.out.println(" ~" + num1 + " = " + complement1);
System.out.println(" ~" + num2 + " = " + complement2);
System.out.println();
System.out.println("按位与:");
System.out.println(num1 + " & " + num2 + " = " + andResult);
System.out.println();
System.out.println("按位或:");
System.out.println(num1 + " | " + num2 + " = " + orResult);
System.out.println();
System.out.println("按位异或:");
System.out.println(num1 + " ^ " + num2 + " = " + xorResult);
}
}
public class Test {
private static int value=1;
public static void main(String[] args) {
int value=2;
System.out.println(value);
}
}
最后输出2
int X=100;
int Y=200;
System.*out*.println("X+Y="+X+Y);
System.*out*.println(X+Y+"=X+Y");
代码的结果:X+Y=100200
public static class Main{
public static void main(String[] args) {
System.out.println("0.51+0.1="+(0.51+0.01));
System.out.println("1.0-0.42="+(1.0-0.42));
System.out.println("4.015*100="+(4.015*100));
System.out.println("123.3/100="+(123.3/100));
}
}
最终结果为
0.51+0.1=0.52
1.0-0.42=0.5800000000000001
4.015*100=401.49999999999994
123.3/100=1.2329999999999999
标签:num1,num2,int,代码,System,测试,println,课堂,out From: https://www.cnblogs.com/4a5r/p/17704647.html