Tassos

π.χ. : #1 - Χωρίς αντικειμενοστραφή σκέψη.

Mar 16th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. {                                      Visit:   http://g-lts.info/  for more code!                            }
  2.  
  3.  
  4. package first;
  5.  
  6. import java.util.Scanner;
  7.  
  8.  
  9.  
  10. public class Main {
  11.    
  12.    
  13.     public static void main (String[] args)
  14.     {
  15.         Scanner in = new Scanner(System.in);
  16.        
  17.         String best_name = "";
  18.         double best_price = 1;
  19.         int best_score = 0;
  20.        
  21.         boolean more = true ;
  22.        
  23.         while ( more )
  24.         {
  25.            
  26.             String next_name;
  27.             double next_price;
  28.             int next_score;
  29.            
  30.             System.out.println("Please enter the product name : ");
  31.             next_name = in.nextLine();
  32.            
  33.             System.out.println("Please enter the product price : ");
  34.             next_price = in.nextDouble();
  35.            
  36.             System.out.println("Please enter the product score : ");
  37.             next_score = in.nextInt();
  38.            
  39.            
  40.             if ( (next_score / next_price) > (best_score / best_price) )
  41.             {
  42.                 best_name = next_name;
  43.                 best_price = next_price;
  44.                 best_score = next_score;
  45.             }
  46.            
  47.            
  48.             System.out.println("More data ? (1=Yes , 2=No) :");
  49.             int answer = in.nextInt();
  50.            
  51.             if ( answer != 1 )
  52.                 more = false;
  53.             in.nextLine();
  54.            
  55.            
  56.         }
  57.        
  58.         System.out.println("The best product is : " + best_name);
  59.         System.out.println("The best price is : " + best_price);
  60.         System.out.println("The best score is : " + best_score);
  61.  
  62.        
  63.        
  64.     }
  65.  
  66. }
  67.  
  68.  
  69.  
  70. {                                      Visit:   http://g-lts.info/  for more code!                            }
Advertisement
Add Comment
Please, Sign In to add comment