输入数字n,下面输入n行字符串型
package exambytedancetest1;
import java. util. *;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
int n = sc. nextInt ( ) ;
sc. nextLine ( ) ;
while ( n > 0 ) {
n-- ;
String s = sc. nextLine ( ) ;
}
}
}
链接 参考
import java. util. *;
public class OJ {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
int a = sc. nextInt ( ) ;
int b = sc. nextInt ( ) ;
System. out. println ( a+ b) ;
}
}
}
import java. util. *;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
int n = sc. nextInt ( ) ;
for ( int i = 0 ; i < n; i++ ) {
int a = sc. nextInt ( ) ;
int b = sc. nextInt ( ) ;
System. out. println ( a+ b) ;
}
}
}
import java. util. *;
public class Main {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
while ( sc. hasNext ( ) ) {
int a = sc. nextInt ( ) ;
int b = sc. nextInt ( ) ;
if ( a == 0 & b == 0 ) {
break ;
}
System. out. println ( a+ b) ;
}
}
}
import java. util. *;
public class OJ {
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
int n;
while ( ( n = sc. nextInt ( ) ) != 0 ) {
int sum = 0 ;
for ( int i = 0 ; i< n; i++ ) {
sum += sc. nextInt ( ) ;
}
System. out. println ( sum) ;
}
}
}
输入一行整型数组
public static void main ( String[ ] args) {
Scanner sc= new Scanner ( System. in) ;
String[ ] nums = null;
nums = sc. nextLine ( ) . split ( " " ) ;
int num[ ] = new int [ nums. length] ;
for ( int i= 0 ; i< num. length; i++ ) {
num[ i] = Integer. valueOf ( nums[ i] ) ;
}
}