import java.util.Scanner;
public class java4 {
public static void main(String[] args) {
Scanner i=new Scanner(System.in);
int a=i.nextInt();
int b=i.nextInt();
if(a>100&&a<10);
{System.out.println("输入错误,请输入两位数!");
};
if(b>100&&b<10);
{System.out.println("输入错误,请输入两位数!");}
{System.out.println(a+b);}
}
}
帮忙改下吧,谢谢啦!
import java.util.Scanner;
public class Program1 {
public static void main(String[] args) {
Scanner i = new Scanner(System.in);
int a = i.nextInt();
int b = i.nextInt();
if (a > 100 || a < 10 || b>100 ||b<10) {
System.out.println("输入错误,请输入两位数!");
}else{
System.out.println(a + b);
}
}
}
java的用法小结
一、简单的stream,parallelStream慎用
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
list.parallelStream().forEach(System.out::println);
list.parallelStream().forEachOrdered(System.out::println);
二、简单的stream, collect, sum, count,
1、取某一字段 stream & collect
System.out.println(userList.stream().map(User::getAddress).collect(Collectors.toList()));
System.out.println("---------");
ArrayList<String> arrayList =
userList.stream().map(User::getAddress).collect(Collectors.toCollection(ArrayList::new));
System.out.println(arrayList);
System.out.println("---------");
System.out.println(userList.stream().map(User::getAddress).collect(Collectors.joining("@@")));
2、取总和 sum
System.out.println(userList.stream().mapToInt(User::getAge).sum());
3、分组
Map<String, List<User>> addressMap =
userList.stream().collect(Collectors.groupingBy(User::getAddress));
System.out.println(addressMap);
public static void mian(String[] args) {
System.out.println("请输入被加数a:");
Scanner scanner1 = new Scanner(System.in);int num1 = scanner1.nextInt();
System.out.println("请输入被加数b");int num2 = scanner2.nextInt();
int sum = add(num1,num2);完整代码如下:
package testcode;
import java.util.Scanner;
public class PAT1001 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner=new Scanner(System.in);
int a=Integer.parseInt(scanner.next());
int b=Integer.parseInt(scanner.next());
Integer c=a+b;
String s = c.toString();
char[] strings2 = s.toCharArray();
int num;
char[] output;
int i=0,k;
if (strings2[0]=='-') {
if ((strings2.length-1)%3==0) {
num=(strings2.length-4)/3;
}else {
num=(strings2.length-1)/3;
}
output=new char[strings2.length+num];
i=0;
k=output.length;
for (int j = strings2.length-1; j >=0 ; j--) {
i++;
k--;
if (i%3==0&&k>=2) {
output[k]=strings2[j];
k--;
if(k>=0){
output[k]=',';
}
}else{
output[k]=strings2[j];
}
}
}else{
if (strings2.length%3==0) {
num=(strings2.length-3)/3;
}else {
num=strings2.length/3;
}
output=new char[strings2.length+num];
i=0;
k=output.length;
for (int j = strings2.length-1; j >= 0; j--) {
i++;
k--;
output[k]=strings2[j];
if(i%3==0){
k--;
if(k>=0){
output[k]=',';
}
}
}
}
System.out.println(output);
}
}
拓展:程序目的是将形如-23455066,2345539转化成-23,455,066,2,345,539形式。用到的主要方法是String的toCharArray()方法,该方法将字符串转化成字符数组,获取到数组后就可以利用其进行修改,
本回答被网友采纳用Java编写程序 任意两个输入两个整数 输出它们相加的结果
import java.util.Scanner;public class Program1 {public static void main(String[] args) {Scanner i = new Scanner(System.in);int a = i.nextInt();int b = i.nextInt();if (a > 100 || a < 10 || b>100 ||b<10) { System.out.println("输入错误,请输入两位数!");}el...
Java编程,输入两个数,输出两个数的和。
这个程序核心是Scanner类的使用 package com.test;import java.util.Scanner;public class Test {public static void main(String[] args)throws Exception{Scanner s= new Scanner(System.in);System.out.print("输入第一个数:");float a=s.nextFloat();System.out.print("输入第二个数:");floa...
Java编程,输入两个数,输出两个数的和。
当然可以!以下是一个简单的Java程序,它接受两个数作为输入,并输出它们的和:javaimport java.util.Scanner; public class SumCalculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("请输入第一个数:"); double n...
用java实现输入两个二进制数并仍然以二进制输出其和,不能用先转十进制...
两个数相加,会得到一个结果,和一个进位的结果,然后将这个进位的结果后面加0补位,然后再和这个结果相加。如此递归,知道进位全部是0为止 public class $ { public static void main(String[] args) { String s0 = "100";\/\/ 十进制4 String s1 = "10100";\/\/ 十进制20 StringB...
用JAVA编写 输入2个整数 num1 和 num2,计算并输出它们的和、差、积...
public static void main(String args[]) { int num1, num2;Scanner in = new Scanner(System.in);num1 = in.nextInt();num2 = in.nextInt();\/** 添加 *\/ long sum = num1 + num2;long sub = num1 - num2;long mul = num1 * num2;int div, mod;\/\/ 除法要判断除数是否为...
java任意输出两个正整数,计算并打印出两个整数之间所有整数和
直接上代码:java.util.Random random = new java.util.Random();int a = random.nextInt(100);int b = random.nextInt(100);System.out.println("两个数:" + a + ", " + b);int min = a;int max = b;if (a > b) {min = b;max = a;}int sum = 0;for (int i = (...
用Java编写程序在控制台窗口中提示输入两个整数,然后接收这两个整数,并...
import java.util.Scanner;public class PrintInt { public static void main(String[] args) { String a,b;Scanner scan = new Scanner(System.in);while(true){ System.out.println("输入第一个整数 : ");a = scan.next();System.out.println("输入第二个整数 :");b = scan.next()...
根据JAVA用户输入两个整数,分别输出这两个数的和、差、积、商._百度知...
import java.util.Scanner;public class putin { public static void main(String[] args){ Scanner s = new Scanner(System.in);System.out.println("现在可以输入一个数字。整数或者是小数:");int i = 0;int x = 0;int y = 0;while(s.hasNext()){ i++;if( 1 == i){ x = s....
...输出为两个整数的和,单独占一行。 用java编写 谢谢
import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入两个整数,以空格隔开");String num = sc.nextLine();System.out.println(num);System.out.println("两个数的和为:" + (Integer....
JAVA从键盘输入2个数字,输出两个数字的“+、-、*、\/、%”的运算表达式...
import java.util.Scanner;public class Test01 { public static void main(String[] args) { Scanner scan=new Scanner(System.in);float num1,num2;System.out.print("请输入两个数!\\n第一个数:");num1=scan.nextFloat();System.out.print("第二个数:");num2=scan.nextFloat();System....