You are not logged in. Please login at www.codechef.com to post your questions!

×

Return statement problem

import java.io.File;

import java.util.Scanner;

public class RandomMovie {

public int randomNumber() throws Exception{
    File file = new File("movies.txt");
    Scanner scanner = new Scanner(file);

    int randomRange = 0;
    int Random;


    while(scanner.hasNextLine()){
        String line = scanner.nextLine();
        randomRange++;
    }
    Random = (int) ((Math.random() * randomRange) + 1);

    /*      Test randomRange
    for (int i=Random; i<=25;Random = (int) ((Math.random() * randomRange) + 1)) {
        System.out.println(Random);
    }
    */

    return Random;
}


public String randomMovie() throws Exception{
    File file = new File("movies.txt");
    Scanner scanner = new Scanner(file);

    //Bring the Random Movie
    int counter = 1;
    String Movie;


    while(scanner.hasNextLine() && counter == randomNumber()){
        String finalLine = scanner.nextLine();
        Movie = finalLine;
        counter++;
    }
    return Movie;
}

}

The problem in the second function randomMovie() in return Movie;

alt text

asked 11 Jan, 02:05

samy007's gravatar image

0★samy007
11
accept rate: 0%

edited 11 Jan, 02:13

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,277
×646
×516
×46
×27
×24
×15
×7

question asked: 11 Jan, 02:05

question was seen: 29 times

last updated: 11 Jan, 02:13