Free2Code
 
Time: 2008-12-04, 07:48pm
can some one tell me
Subject: can some one tell me  ·  Posted: 2007-02-01, 10:03am
Rank: ? (8)
Member #: 25317
can some one tell were i am gong wrong

Code:
  1. import java.io.*;
  2. import java.util.*;
  3. import java.math.*; 
  4. public class plan
  5. {
  6.   private double num1;
  7.   private double num2;
  8.   private double num3;  
  9.  private static Scanner input =new Scanner(System.in);{
  10.   public static void main (String [] args)
  11.     
  12.    {
  13.    
  14.    switch (case1, case2, case3)
  15.    {
  16.     System.out.println ("enter a number between 1 and 3")
  17.     double num1, num2, num3 = input.nextDouble(); 
  18.     case 1 : System.out.println ("number is 1"); break;
  19.     case 2 : System.out.println ("number is 2"); break;
  20.    
  21.     case 3 : System.out.println ("number is 3"); break;
  22.     default: System.out.println ("other nuber");
  23.                                               }
  24.     }
  25.     System.out.println("Program ends");
  26.   }
  27. }



by there way i am a begginer at this and this is wat i made from the top of my head

» Post edited 2007-02-05, 04:04am by misterhaan.

 
  Reply to this ·  Post link ·  Top
Subject: Re: can some one tell me  ·  Posted: 2007-02-05, 04:08am
Rank: ? (4821)
Member #: 3416
on line 25, your switch statement is invalid. it should be in the format switch(expression), but you have case1, case2, case3. i'm not even sure what you mean by that since none of those are variables. my guess is that you want to do the switch statement on the value you read from input, so it should be after you read a value from input.

on line 29, you redeclare num1, num2, and num3 as double (they are already declared as double in lines 11-13). that means they only exist within the current set of braces, and in the case of this particular program, makes the ones declared on lines 11-13 useless. also, only num3 is getting a value here.

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
Subject: Re: can some one tell me  ·  Posted: 2007-03-28, 11:04am
Rank: ? (6)
Member #: 29111
oh yeah ronny said thanks

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons