展开全部
import java.util.Scanner;
public static void main(String[] args) {
int sum=0;
boolean flag=true;
Scanner scan = new Scanner(System.in);
System.out.println("请输入您的卡号(4位数字):");
String str = scan.nextLine();
for(int i=0;i<4;i++) {
sum+=str.charAt(i)-'0';
if(str.charAt(i)=='8'||(i==3&&sum%8!=0)) {flag=false;break;}
}
System.out.println("您的卡号个位为:"+str.charAt(3));
System.out.println("您的卡号十位为:"+str.charAt(2));
System.out.println("您的卡号百位为:"+str.charAt(1));
System.out.println("您的卡号千位为:"+str.charAt(0));
System.out.println("您的卡号所有数字之和为:"+(str.charAt(0)+str.charAt(1)+str.charAt(2)+str.charAt(3)-'0'*4));
System.out.println("您是否中奖:"+flag);
}
追问
,
展开全部
package lianxi;
import java.util.Scanner;
public class Demo04 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的卡号(4位数字);");
int num = sc.nextInt();
//个
int units = num%10;
//十
int tens = (num/10)%10;
//百
int hundreads = (num/100)%10;
//万
int thousands = (num/1000)%10;
//所有数字之和
int sum = units+tens+hundreads+thousands;
System.out.println("您的卡号个位为:"+units);
System.out.println("您的卡号十位为:"+tens);
System.out.println("您的卡号百位为:"+hundreads);
System.out.println("您的卡号万位为:"+thousands);
System.out.println("您的卡号所有数字之和为:"+sum);
if(sum%8==0 && units!=8 && tens!=8 && hundreads!=8 && thousands!=8) {
System.out.println("您是否中奖:"+true);
}else {
System.out.println("您是否中奖:"+false);
}
}
}
import java.util.Scanner;
public class Demo04 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的卡号(4位数字);");
int num = sc.nextInt();
//个
int units = num%10;
//十
int tens = (num/10)%10;
//百
int hundreads = (num/100)%10;
//万
int thousands = (num/1000)%10;
//所有数字之和
int sum = units+tens+hundreads+thousands;
System.out.println("您的卡号个位为:"+units);
System.out.println("您的卡号十位为:"+tens);
System.out.println("您的卡号百位为:"+hundreads);
System.out.println("您的卡号万位为:"+thousands);
System.out.println("您的卡号所有数字之和为:"+sum);
if(sum%8==0 && units!=8 && tens!=8 && hundreads!=8 && thousands!=8) {
System.out.println("您是否中奖:"+true);
}else {
System.out.println("您是否中奖:"+false);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询