基础代码,就不打注释了,望采纳
成都创新互联公司专注于道外网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供道外营销型网站建设,道外网站制作、道外网页设计、道外网站官网定制、小程序设计服务,打造道外网络公司原创品牌,更为您提供道外网站排名全网营销落地服务。
public class Test{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入数字");
int i = sc.nextInt();
if(i%2==0){
System.out.println("偶数");
}else{
System.out.println("奇数");
}
if(i0){
System.out.println("正数");
}else if(i0){
System.out.println("负数");
}else{
System.out.println("0");
}
}
}
首先介绍下:质数是除了本身和1以外,没有质因数,就是没有数能够整除之;合数是除了本身和1以外还有第三个数能整除之。
具体示例代码如下:
public class Demo2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("请输入一个数:");
int num = scan.nextInt();
int index = 0;//使用一个数来标记是质数还是合数
for (int i = 2; i num; i++) {
if (num % i == 0) {
index++;
}
}
if (index == 0) {//index等于0表示质数
System.out.println("这是个质数");
}
else {//index大于0表示合数
System.out.println("这是个合数");
}
}
}
需要注意的是:1不算质数也不算合数。
问题的思路大概如此,1:根据姓名去emp表查询可以统计一个count。 2:判断count是否大于0,如果大于0走els,(count的数字也可能大于1,所以else里面根据name获取一个list)。3:for循环循环list,new一个tb_teleponebook的实体,将id set进userid字段。保存tb_teleponebook实体即可。
public static void main(String[] args) {
char name;
double total = 0;
int count = 0;
double c = 0;
int ftax = 0;
double hcost = 0;
Scanner kbd = new Scanner(System.in);
System.out.print("Please enter item name, Q to quit:");
name = kbd.next().charAt(0);
while (name != 'Q' name != 'q') {
System.out.print("Please enter cost:");
double cost = kbd.nextInt();
if (!isValid(cost)) {
continue;
}
if (cost = hcost) {
hcost = cost;
}
System.out.print("Please enter tax rate:");
int tax = kbd.nextInt();
if (tax == 0) {
ftax = ftax + 1;
}
c = calculateFinalCost(cost, tax);
System.out.println(name + " costs " + c + " (plus " + tax + "% tax)");
total = total + c;
count = count + 1;
System.out.print("Please enter item name, Q to quit:");
name = kbd.next().charAt(0);
}
if (count == 0) {
System.out.println("No items entered");
System.out.println("Thanks for shopping with JMart");
} else {
System.out.println("Average cost: " + total / count);
System.out.println("Number of items with no tax:" + ftax);
System.out.println("Highest cost:" + hcost);
System.out.println("Thanks for shopping with JMart");
}
}
public static boolean isValid(double cost) {
if (cost 0) {
return true;
}
return false;
}