2016-04-10 8 views
0
import java.util.Scanner; 
import java.io.*; 

public class Solution { 

public static void main(String[] args) { 
     Scanner sc=new Scanner(System.in); 
     int x=sc.nextInt(); 

     Double y= sc.nextDouble(); 
     Scanner sc1=new Scanner(System.in); 
     String name = sc1.nextLine(); 


     System.out.println("String: "+name); 
     System.out.println("Double: "+y); 
     System.out.println("Int: "+x); 
} 
} 

girişi: ('ram' daha önce sahip 5 alanı)Java'da tarayıcı kullanarak dize öncesi boşluk nasıl okunur?

343434343

343.434343

ram sdf

Beklenen çıkışı ('ram' önce 5 alana sahip)

ram sdf

343.434343

343434343

cevap

1

İki tarayıcılar oluşturmak zorunda değilsiniz. Ayrıca, çift okuduğunuzda nextLine() yapmalısınız.

public static void main (String[] args) throws Exception { 
    Scanner sc = new Scanner(System.in); 
    int x = sc.nextInt(); 
    Double y = sc.nextDouble(); 

    /* Note the change here */ 
    sc.nextLine(); 
    String name = sc.nextLine(); 

    System.out.println("String: " + name); 
    System.out.println("Double: " + y); 
    System.out.println("Int: " + x); 
} 

Çıktı:

String:  ram sdf 
Double: 343.434343 
Int: 343 
İşte

düzeltilmiş kod parçacığı olduğunu
İlgili konular