import java.lang.*;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in =new Scanner(System.in);
while(in.hasNextInt()){//下一行是否有數(shù)據(jù)
int a=in.nextInt();
int b=in.nextInt();
System.out.println(a+b);
}
}
}
Java方法間的調(diào)用
https://blog.csdn.net/m0_65627943/article/details/129214520文章來源:http://www.zghlxwxcb.cn/news/detail-668090.html
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 靜態(tài)只能調(diào)用靜態(tài)?。。。。。。。。。。?
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;/注意
}
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-668090.html
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);
// 輸出第二行到倒數(shù)第二行
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()是以回車作為結(jié)束符的,不會讀回車
next() 是以空格、回車為結(jié)束字符的

上面不用arraylist是因為arraylist的tostring不能直接輸出字符串要遍歷

hasNext hasNextLine區(qū)別:**https://www.yii666.com/blog/378032.html**
到了這里,關(guān)于ACM模式(基礎(chǔ)輸入輸出)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!