标签:nal gif dem constrain join tab div dsc string
public class DEMO01 {
public static void main(String[] args) {
int a1=1,a2=1;
int b,c;
b=++a1; //先把a1自加1,然后再赋给b
c=a2++; //先把a2原本的值(即1)赋给c,然后再自加1
System.out.println(b);
System.out.println(c);
}
}
x?y:z //x若是真,则结果为y,否则是z。
public class DEMO01 {
public static void main(String[] args) {
int score=60;
String chengji =score>=60?"及格":"不及格"; //定义字符串变量chengji,如果score>=60 为真,则输出“及格”,否则输“不及格”
System.out.println(chengji);
}
}
package Scaner;
import com.sun.org.apache.xalan.internal.res.XSLTErrorResources;
import java.util.Scanner;
public class Demo03 { //判断输入是为是整数,判断小数是同理。KS P34
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("请输入整数");
if(scanner.hasNextInt()){
int i =scanner.nextInt();
System.out.println("输出为\n"+i);
}
else
System.out.println("你输入的不是整数!");
scanner.close();
}
}
//从键盘输入多个数字,且算出总和和平均数 KS P34后半部分
package Scaner;
import java.util.Scanner;
public class Demo04 {
public static void main(String[] args) {
Scanner scanner= new Scanner(System.in);
double a=0;
double sum=0;
int i=0;
System.out.println("请输入");
while(scanner.hasNextDouble()) { //用while可以实现多次输入,如果你用if,只能输入一个数字就终止了。
a = scanner.nextDouble();
sum=a+sum;
i=i+1;
System.out.println("当前是第"+i+"数");
System.out.println("总和为"+sum);
System.out.println("平均数是"+sum/i);
}
scanner.close();
}
}
标签:nal gif dem constrain join tab div dsc string
原文地址:https://www.cnblogs.com/llgg/p/13457837.html