当前位置: 首页>>代码示例>>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;未经允许,请勿转载。