英文:
input number then take numbers front and back
问题
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int enter1, nominal, hundreds;
System.out.print("输入数字:");
enter1 = input.nextInt();
hundreds = enter1 % 1000;
nominal = enter1 % 100;
System.out.println("前置数字:" + hundreds);
System.out.println("后置数字:" + nominal);
}
英文:
I am trying to make this work, but I cannot.
The input for:
Enter number : 12345
should be:
front numbers:123
back numbers:45
Another example:
Enter number : 485
the output:
front numbers:4
back numbers:85
Another example:
Enter number : 4370
the output:
front numbers:43
back numbers:70
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int enter1, nominal, hundreds;
System.out.print("enter number : ");
enter1 = input.nextInt();
hundreds = enter1%1000;
nominal = enter1%100;
System.out.println("front numbers = " + hundreds);
System.out.println("back numbers = " + nominal);
}
答案1
得分: 0
你离目标很近:hundreds = enter1%1000;
应更改为 hundreds = enter1 / 100;
Scanner scan = new Scanner(System.in);
System.out.print("输入数字:");
int num = scan.nextInt();
System.out.println("前部数字 = " + num / 100);
System.out.println("后部数字 = " + num % 100);
英文:
You're almost there: hundreds = enter1%1000;
should be hundreds = enter1 / 100;
Scanner scan = new Scanner(System.in);
System.out.print("enter number: ");
int num = scan.nextInt();
System.out.println("front numbers = " + num / 100);
System.out.println("back numbers = " + num % 100);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论