输入数字,然后获取数字前面和后面的数字。

huangapple go评论54阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2020年9月24日 02:03:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/64033826.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定