import java.lang.*;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in =new Scanner(System.in);
while(in.hasNextInt()){//下一行是否有数据
int a=in.nextInt();
int b=in.nextInt();
System.out.println(a+b);
}
}
}
Java方法间的调用
https://blog.csdn.net/m0_65627943/article/details/129214520
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scanner =new Scanner(System.in);
while(scanner.hasNextLine()){
String line=scanner.nextLine();//没有nextChar()!!!!!!!!1
String[] scores=line.split(" ");/
double num=convert(scores);
if(num<0){
System.out.println("Unknown");
}else{
System.out.printf("%.2f\n",num);//注意printf
}
}
}
public static double convert(String[] strs){//注意static 静态只能调用静态!!!!!!!!!!!1
double sum=0;///注意
for(String str:strs){
int a=-1;
if(str.equals("A")){//注意字符串比较
a=4;
}else if(str.equals("B")){
a=3;
}else if(str.equals("C")){
a=2;
}else if(str.equals("D")){
a=1;
}else if(str.equals("F")){
a=0;
}else{
return a;
}
sum+=a;
}
return sum*1.0/strs.length;/注意
}
}
import java.util.Scanner;
//很重要多看看!!!!!!!!!!!!!!!!!!!!!
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String line = sc.nextLine();
if (line.equals("@"))
break;
String[] inputs = line.split(" ");
char ch = inputs[0].charAt(0);
int n = Integer.parseInt(inputs[1]);
// 输出图案
printPattern(ch, n);
}
sc.close();
}
private static void printPattern(char ch, int n) {
// 输出第一行
print(' ', n - 1);
System.out.println(ch);
// 输出第二行到倒数第二行
for (int i = 2; i < n; i++) {
print(' ', n - i);
System.out.print(ch);
print(' ', 2 * i - 3);
System.out.println(ch);
}
// 输出最后一行
if (n > 1) {
print(ch, 2 * n - 1);
System.out.println();
}
System.out.println();
}
private static void print(char ch, int count) {
while (count-- > 0) {
System.out.print(ch);
}
}
}
``aa bb cc 回车 nextLine()是以回车作为结束符的,不会读回车
next() 是以空格、回车为结束字符的
![在这里插入图片描述](https://img-blog.csdnimg.cn/8782fc3af4b5420580965b056d2f1dcc.png)
上面不用arraylist是因为arraylist的tostring不能直接输出字符串要遍历
![在这里插入图片描述](https://img-blog.csdnimg.cn/9f1c13c1065b42e6b5e1f44e01ae539e.png)
hasNext hasNextLine区别:**https://www.yii666.com/blog/378032.html**