From 73749e4f9c8904d561d3b1fa17136c3af03efd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8F=AD=E9=98=B3=E4=B8=BD?= <2431466589@qq.com> Date: Thu, 11 May 2023 11:58:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230510 \345\274\202\345\270\270.txt" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "37 \346\217\255\351\230\263\344\270\275/20230510 \345\274\202\345\270\270.txt" diff --git "a/37 \346\217\255\351\230\263\344\270\275/20230510 \345\274\202\345\270\270.txt" "b/37 \346\217\255\351\230\263\344\270\275/20230510 \345\274\202\345\270\270.txt" new file mode 100644 index 0000000..27a46d0 --- /dev/null +++ "b/37 \346\217\255\351\230\263\344\270\275/20230510 \345\274\202\345\270\270.txt" @@ -0,0 +1,28 @@ +```java +import java.util.Scanner; + +public class A1 { + //让用户输入两个整数,求和 + //用户可能会输入非整数的值,比如字符串,小数 + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入一个整数"); + int a=sc.nextInt(); + System.out.println("请输入一个整数"); + int b=sc.nextInt(); + while (true){ + try { + int a1=Integer.bitCount(a); + int b1=Integer.bitCount(b); + System.out.println("和为"+(a+b)); + break; + } catch (NumberFormatException e) { + System.out.println("输入错误,请重新输入"); + } + + + } + + } +``` + -- Gitee