herrDeng網內搜尋

自訂搜尋

Ads

2012年3月8日 星期四

用Scanner時小心nextLine()



我想要輸入int i 後,在輸入String s,可是讀完i,就跳走了,怎麼修改程式?

9 則留言:

B9833080 提到...

import java.util.*;
public class scannerDotNextLine {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();//修改部分
System.out.println("輸入字串s="+s);
}
}

B9833080 提到...

import java.util.*;
public class scannerDotNextLine {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();//修改部分
System.out.println("輸入字串s="+s);
}
}

B10033005 提到...

import java.util.*;
public class scannerDotNextLine {
public static void main (String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();
System.out.println("輸入字串s="+s);
}


}

b10033017 提到...

import java.util.*;
public class scannerDotNextLine {
public static void main (String[] args) {
Scanner input=new Scanner (System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();
System.out.println("輸入字串s="+s);
}
}

B10033052 提到...

import java.util.*;
public class scannerDotNextLine {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+1);
String s=input.nextInt();
s=input.nextInt();
System.out.println("輸入字串s="+s);
}
}

b10033016 提到...

import java.util.*;
public class scannerDotNextLine{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();
System.out.println("輸入字串s="+s);
}
}

B10033035 提到...

import java.util.*;
public class scannerDotNextLine{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();
System.out.println("輸入字串s="+s);
}
}

b9733191 提到...

import java.util.*;
public class scannerDotNextLine {
public static void main (String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();
System.out.println("輸入字串s="+s);
}


}

B10033011 提到...

import java.util.*;
public class scannerDotNextLine{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i=input.nextInt();
System.out.println("輸入i="+i);
String s=input.nextLine();
s=input.nextLine();
System.out.println("輸入字串s="+s);
}
}

Related Posts Plugin for WordPress, Blogger...

熱門文章