當前位置: 首頁>>代碼示例>>Java>>正文


Java Scanner.next方法代碼示例

本文整理匯總了Java中java.util.Scanner.next方法的典型用法代碼示例。如果您正苦於以下問題:Java Scanner.next方法的具體用法?Java Scanner.next怎麽用?Java Scanner.next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Scanner的用法示例。


在下文中一共展示了Scanner.next方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getResponseFromHttpUrl

import java.util.Scanner; //導入方法依賴的package包/類
/**
 * This method returns the entire result from the HTTP response.
 *
 * @param url The URL to fetch the HTTP response from.
 * @return The contents of the HTTP response.
 * @throws IOException Related to network and stream reading
 */
public static String getResponseFromHttpUrl(URL url) throws IOException {
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        InputStream in = urlConnection.getInputStream();

        Scanner scanner = new Scanner(in);
        scanner.useDelimiter("\\A");

        boolean hasInput = scanner.hasNext();
        if (hasInput) {
            return scanner.next();
        } else {
            return null;
        }
    } finally {
        urlConnection.disconnect();
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:26,代碼來源:NetworkUtils.java

示例2: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) {
    Ato0 a0 = new Ato0();
    Scanner input = new Scanner(System.in);
    System.out.println("Olá jogador, qual o seu nome?");
    String nome = input.next();
    System.out.println(nome + " Qual especialidade você quer ter?");
    System.out.println(" 1 - Arqueiro - ");
    System.out.println(" 2 - Guerreiro - ");
    System.out.println(" 3 - Mago - ");
    int especialidade;
    especialidade = input.nextInt();
    System.out.println("Então " + nome + " qual raça você gostaria de ser?");
    System.out.println("1 - Anão - ");
    System.out.println("2 - Elfo - ");
    System.out.println("3 - Humano - ");
    System.out.println("4 - Orc - ");
    System.out.println("5 - Undead - ");
    int raca;
    raca = input.nextInt();
    Ato1 as = new Ato1(a0.criarJogador(nome, EnumEspecialidades.values()[especialidade], EnumRacas.values()[raca]));
    as.abrirInventario(as.getDispensa(), "dispensa");
}
 
開發者ID:vagnerereno,項目名稱:RPII,代碼行數:23,代碼來源:Ato1.java

示例3: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[ ] args) 
{
	Scanner sc = new Scanner(System.in);
	String userName = "jim";
	String password = "123456";
	for(int a =2 ; a >= 0 ; a--)
	{	
		System.out.print("\n請輸入用戶名:");
		String userName1 = sc.next();
		System.out.print("請輸入密碼:");
		String password1 = sc.next();
		if("jim".equals(userName1) && "123456".equals(password1))
		{
			System.out.print("\n歡迎登錄MyShopping係統!");
			break;
		}
		if(a == 0)
		{
			System.out.print("\n對不起,您三次輸入均錯誤");
			break;
		}
		System.out.print("輸入錯誤!您還有" + a + "次機會");
	}
	sc.close();
}
 
開發者ID:JAVA201708,項目名稱:Homework,代碼行數:26,代碼來源:Login.java

示例4: getResponseFromHttpUrl

import java.util.Scanner; //導入方法依賴的package包/類
/**
 * This method returns the entire result from the HTTP response.
 *
 * @param url The URL to fetch the HTTP response from.
 * @return The contents of the HTTP response, null if no response
 * @throws IOException Related to network and stream reading
 */
public static String getResponseFromHttpUrl(URL url) throws IOException {
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
        InputStream in = urlConnection.getInputStream();

        Scanner scanner = new Scanner(in);
        scanner.useDelimiter("\\A");

        boolean hasInput = scanner.hasNext();
        String response = null;
        if (hasInput) {
            response = scanner.next();
        }
        scanner.close();
        return response;
    } finally {
        urlConnection.disconnect();
    }
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:27,代碼來源:NetworkUtils.java

示例5: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int length = scan.nextInt();
    String str = scan.next();
    int K      = scan.nextInt();
    scan.close();
    
    StringBuilder sb = new StringBuilder();
    
    for (int i = 0; i < length; i++) {
        char ch = str.charAt(i);
        sb.append(encrypt(ch, K));
    }
    
    System.out.println(sb);
}
 
開發者ID:rshaghoulian,項目名稱:HackerRank_solutions,代碼行數:17,代碼來源:Solution.java

示例6: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args)
{
	Scanner sc = new Scanner(System.in);
	Dog dog = new Dog();

	System.out.println("歡迎來到寵物店!");
	System.out.println("請輸入要領養的寵物的名字:");
	String name = sc.next();
	System.out.println("請選擇要領養的寵物類型:(1、狗狗2、企鵝)");
	int type = sc.nextInt();
	switch (type)
	{
	case 1:
		dog.setName(name);
		System.out.println("請選擇狗狗的品種:1、聰明的拉布拉多2、酷酷的雪納瑞");
		int strain = sc.nextInt();
		switch (strain)
		{
		case 1:
			dog.setStrain("聰明的拉布拉多");
			break;
		case 2:
			dog.setStrain("酷酷的雪納瑞");
			break;
		}
		System.out.println("請輸入狗狗的健康值(1~100):");
		dog.setHealth(sc.nextInt());
		dog.play();
		break;
	case 2:
		System.out.println("請選擇企鵝的品種:1、Q妹2、Q仔");
		break;
	default:
		System.out.println("請選擇狗狗的品種:輸入錯誤!");
	}

}
 
開發者ID:JAVA201708,項目名稱:Homework,代碼行數:38,代碼來源:OOEX03.java

示例7: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str   = scan.next();
    int n        = scan.nextInt();
    HashSet<Integer> weights = getWeights(str);
    while (n-- > 0) {
        int x = scan.nextInt();
        System.out.println(weights.contains(x) ? "Yes" : "No");
    }
    scan.close();
}
 
開發者ID:rshaghoulian,項目名稱:HackerRank_solutions,代碼行數:12,代碼來源:Solution.java

示例8: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String []args) {
    Scanner in = new Scanner(System.in);
    while(in.hasNext()) {
        String IP = in.next();
        System.out.println(IP.matches(new MyRegex().pattern));
    }
}
 
開發者ID:MohamedSondo,項目名稱:ACE_HackerRank,代碼行數:8,代碼來源:Solution.java

示例9: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    Trie trie = new Trie();
    for (int i = 0; i < n; i++) {
        String operation = scan.next();
        String contact   = scan.next();
        if (operation.equals("add")) {
            trie.add(contact);
        } else if (operation.equals("find")) {
            System.out.println(trie.find(contact));
        }
    }
    scan.close();
}
 
開發者ID:rshaghoulian,項目名稱:HackerRank_solutions,代碼行數:16,代碼來源:Solution.java

示例10: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    BigInteger a = new BigInteger(scan.next());
    BigInteger b = new BigInteger(scan.next());
    System.out.println(a.add(b));
    System.out.println(a.multiply(b));
}
 
開發者ID:MohamedSondo,項目名稱:ACE_HackerRank,代碼行數:8,代碼來源:Solution.java

示例11: testUploadAppTemplate

import java.util.Scanner; //導入方法依賴的package包/類
@Test
public void testUploadAppTemplate() throws FileNotFoundException {
    CreateJvmRequest createJvmRequest = new CreateJvmRequest("testJvmName", "testHostName", 9101, 9102, 9103, -1,
            9104, new Path("./"), "", null, null, null, null);

    CreateGroupRequest createGroupReq = new CreateGroupRequest("testGroupName");
    Group group = groupPersistenceService.createGroup(createGroupReq);

    Jvm jvm = jvmPersistenceService.createJvm(createJvmRequest);
    JpaJvm jpaJvm = jvmPersistenceService.getJpaJvm(jvm.getId(), false);

    AddJvmToGroupRequest addJvmGrpRequest = new AddJvmToGroupRequest(group.getId(), jvm.getId());
    group = groupPersistenceService.addJvmToGroup(addJvmGrpRequest);

    CreateApplicationRequest request = new CreateApplicationRequest(group.getId(), "testAppName", "/hctTest", true, true, false);
    Application app = applicationPersistenceService.createApplication(request);

    Application sameApp = applicationPersistenceService.getApplication(app.getId());
    assertEquals(app.getName(), sameApp.getName());

    sameApp = applicationPersistenceService.findApplication(app.getName(), group.getName(), jvm.getJvmName());
    assertEquals(app.getName(), sameApp.getName());

    List<Application> appList = applicationPersistenceService.findApplicationsBelongingToJvm(jvm.getId());
    assertEquals(1, appList.size());
    assertEquals(app.getName(), appList.get(0).getName());

    InputStream dataStream = new FileInputStream(new File("./src/test/resources/ServerXMLTemplate.tpl"));
    Scanner scanner = new Scanner(dataStream).useDelimiter("\\A");
    String templateContent = scanner.hasNext() ? scanner.next() : "";

    UploadAppTemplateRequest uploadAppTemplateRequest = new UploadAppTemplateRequest(app, "ServerXMLTemplate.tpl", "hctTest.xml", jvm.getJvmName(), "meta data", templateContent);

    applicationPersistenceService.uploadAppTemplate(uploadAppTemplateRequest, jpaJvm);

    applicationPersistenceService.removeApplication(app.getId());
    jvmPersistenceService.removeJvm(jvm.getId());
    groupPersistenceService.removeGroup(group.getId());
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:40,代碼來源:AbstractApplicationPersistenceServiceTest.java

示例12: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int T = scan.nextInt();
    for (int i = 0; i < T; i++) {
        String str = scan.next();
        printEvensOdds(str);
    }
    scan.close();
}
 
開發者ID:rshaghoulian,項目名稱:HackerRank_solutions,代碼行數:10,代碼來源:Solution.java

示例13: main

import java.util.Scanner; //導入方法依賴的package包/類
public static void main(String[] args) 
{
	Seller seller = new Seller();
	Excelle excelle = new Excelle();
	Regal regal = new Regal();
	Scanner sc = new Scanner(System.in);
	System.out.println("請輸入銷售人員的姓名");
	final String name = sc.next();
	seller.setName(name);
	System.out.println("請選擇要購買的汽車(1.凱越 2.君威):");
	int choice = sc.nextInt();
	switch (choice) 
	{
		case 1:
			excelle.setType("凱越");
			System.out.println("輸入你要購買的數量:");
			int num = sc.nextInt();
			excelle.setNum(num);
			excelle.println();
			break;
		case 2:
			regal.setType("君威");
			System.out.println("輸入你要購買的數量:");
			num = sc.nextInt();
			regal.setNum(num);
				
			break;
	}
}
 
開發者ID:JAVA201708,項目名稱:Homework,代碼行數:30,代碼來源:Car.java

示例14: next

import java.util.Scanner; //導入方法依賴的package包/類
public static void next() {
	Scanner scan = new Scanner(System.in);
	// 從鍵盤接收數據

	// next方式接收字符串
	System.out.println("next方式接收:");
	// 判斷是否還有輸入
	if (scan.hasNext()) {
		String str1 = scan.next();
		System.out.println("輸入的數據為:" + str1);
	}
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:13,代碼來源:ScannerDemo.java

示例15: parseCommandLine

import java.util.Scanner; //導入方法依賴的package包/類
/**
   * Parse command line options.
   */
  @SuppressWarnings("resource")
private static void parseCommandLine(String[] args) {
    
	int threshold_int=0;
	  
// input: user
     System.out.println("What ratings should be considered as relevant?\n"
     		+ "Please enter a threshold for relevant ratings in the "
     		+ "range from 0 to 3!\nFor example, a value of '0' means "
     		+ "that all ratings greater than 0 are considered as relevant. ");
     
  System.out.println("Your threshold:");
     
  // Initiate a new Scanner
  Scanner userInputScanner = new Scanner(System.in);
    
     String  threshold_user= userInputScanner.next();

     try{
     	threshold_int = new Integer(threshold_user);
     }catch(Exception e)
     {
     	//print message how to use it
     	printUsage();
     	System.exit(1);
     }
     
     //if user input is in the correct range - take it
     if(threshold_int>=0 && threshold_int<4 ){
     	 	
     	switch(threshold_int){
     	
     	case 0:
     		//default case
     		THRESHOLD = COLUMN_NOVICE;
     		break;
     	case 1:
     		//consider all ratings above 1 as relevant
     		//start at COLUMN_INTERMEDIATE
     		THRESHOLD = COLUMN_INTERMEDIATE;
     		break;
     	case 2:
     		//consider all ratings above 2 as relevant
     		//start at COLUMN_EXPERT
     		THRESHOLD = COLUMN_EXPERT;
     		break;
     		
     	//default value is '0' which means all ratings greater than 0 are considered as relevant
     	//start at COLUMN_NOVICE 
     	default: THRESHOLD = COLUMN_NOVICE;
     	
     	}
     }
     else{
     	//error
     	//print message how to use it
     	printUsage();
     	System.exit(1);
     }
   
}
 
開發者ID:SemanticSoftwareLab,項目名稱:ScholarLens,代碼行數:65,代碼來源:GenerateMetrics.java


注:本文中的java.util.Scanner.next方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。