Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Another pair of eyes.

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Another pair of eyes.

    import java.util.Scanner;
     
    public class SHIT {
            public static void main(String[] args) {
     
                    int inputTall = 0;
                    int utholdenhet = 0;
                    int nedre = 0;
                    int ovre = 1;
     
                    Scanner tastatur = new Scanner(System.in); 
     
                    System.out.print("Type a number that you want checked: ");
                    inputTall = tastatur.nextInt();
                    utholdenhet = sjekkTall(inputTall);
     
                    System.out.printf("the Number : %d has the stamina: %d", inputTall, utholdenhet);
                    System.out.print("\nType lower number: ");
                    nedre = tastatur.nextInt();
                    System.out.print("Type higher number: ");
                    ovre = tastatur.nextInt();
     
                    String utskrift = sjekkTallSpenn(nedre, ovre);
            }
     
            private static String sjekkTallSpenn(int nedre, int ovre) {
                    int storsUtholdenhet = 0;
                    int tallet = 0;
                    for(int i = nedre; i > ovre; i++){
                            int utholdenhet = sjekkTall(i);
                            if(utholdenhet > storsUtholdenhet){
                                    storsUtholdenhet = utholdenhet;
                                    tallet = i;
                            }
                    }
                    return "Number " + i + " have the biggest stamina: " + storsUtholdenhet;
            }
     
            public static int sjekkTall(int tall){
                    int utholdenhet = 0;
     
                    while (tall != 1) {
                            if (tall % 2 == 0) {
                                    tall = tall / 2;
                            } else {
                                    tall = tall * 3 + 1;
                            }
                            utholdenhet++;
                    }
     
                    return utholdenhet;
            }
    }
    Last edited by Ripcurl; October 28th, 2010 at 10:32 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Another pair of eyes.

    What's your question? Where are your code tags?

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Another pair of eyes.

    why wount it compile? :/ i can't see the reason..

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Another pair of eyes.

    The problem is here:

    return "Number " + i + " have the biggest stamina: " + storsUtholdenhet;

    i cannot be resolved as a variable.

    You can't use int i outside of your for loop.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. The Following User Says Thank You to JavaPF For This Useful Post:

    Ripcurl (October 28th, 2010)