Results 1 to 6 of 6
  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Problem with given program !!!

    Hii i'm trying to make a program to find largest number but i'm puzzling in my logic i can't create an logic pease help!!!

    thanks

    <code>
    import java.util.*;
    class arra1
    {
    public static void main(String[] args)
    {
    int v=0;
    Scanner in=new Scanner(System.in);
    System.out.println("How much value you want to calculate");
    int arr=in.nextInt();
    int ar[] = new int[arr];
    System.out.println("Enter"+arr +"values to calculate max value" );
    for(int i=0;i<arr;i++)
    {
    ar[v]=in.nextInt(); //i can't understand why it takes v in ar. "ar[v]=in.nextInt(); "

    }

    for(int i=0;i<arr;i++) /** i caan't understand this logic what is happening here..
    {
    if(ar[0]<ar[v])
    ar[0]=ar[v];
    }

    System.out.println("dcfvgb"+ ar[v]);

    }
    }
    </code>

    thanks

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Problem with given program !!!

    i'm puzzling in my logic
    Can you explain your logic in English to show the problems you are having?
    What steps should the program take to find the largest number?
    How would you do it if you were doing it manually?

    Please use [] with the code tags, not <>
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: Problem with given program !!!

    Quote Originally Posted by vknehra10 View Post
    Hii i'm trying to make a program to find largest number but i'm puzzling in my logic i can't create an logic pease help!!!

    thanks

    Java Code:
    import java.util.*;
    class arra1
    {
    public static void main(String[] args)
    {
    	int v=0;
     Scanner  in=new Scanner(System.in);
     System.out.println("How much value you want to calculate");
     int arr=in.nextInt();
     int ar[] = new int[arr];
     System.out.println("Enter"+arr +"values to calculate max value" );
     for(int i=0;i<arr;i++)
     {
    	 ar[v]=in.nextInt();                                 //i can't understand why it takes v in ar. "ar[v]=in.nextInt(); "
    	 
     }
     
     for(int i=0;i<arr;i++)                                     /** i caan't understand this logic what is happening here..
     {
    	 if(ar[0]<ar[v])
    		 ar[0]=ar[v];
     }
     
     System.out.println("dcfvgb"+ ar[v]);
     
    }
    }
    thanks






    actually i don'tknow ....also i just want to make a program to find largest number with array but i am unable to make any logic..

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Problem with given program !!!

    i just want to make a program to find largest number with array
    Before writing any code you should work on making a list of the steps the program needs to take to solve the problem.
    How would you do in manually if you have a stack of playing cards and wanted to find the card with the highest value?
    What steps would you take to search the cards?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: Problem with given program !!!

    i will check all the cards....

    is there any option to chat with you....

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Problem with given program !!!

    i will check all the cards
    Yes that would be required. What decision would you make when you look at each card?
    You need to describe all the steps as simply as possible for the computer.
    Start with the first card? What would you do?
    Now get the second card. What decision would you make?
    Continue with the rest of the cards.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. problem with this program
    By bunty83 in forum New To Java
    Replies: 7
    Last Post: 11-01-2011, 11:05 PM
  2. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  3. Little problem in my program
    By Pojahn_M in forum New To Java
    Replies: 1
    Last Post: 05-24-2011, 11:42 PM
  4. Problem in Program
    By Abbinormal in forum New To Java
    Replies: 9
    Last Post: 01-08-2010, 03:38 AM
  5. Gui program problem..
    By mingming2009 in forum Advanced Java
    Replies: 7
    Last Post: 04-03-2009, 05:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •