A lame calc | and a question about char's

Discussion in 'Programming General' started by /\/\OO please., Oct 13, 2007.

A lame calc | and a question about char's
  1. Unread #1 - Oct 13, 2007 at 7:56 PM
  2. /\/\OO please.
    Joined:
    Oct 13, 2007
    Posts:
    77
    Referrals:
    0
    Sythe Gold:
    0

    /\/\OO please. Member

    A lame calc | and a question about char's

    Code:
    //*Z0mg its a*//
    //*Calculat0r*//
    import java.util.Scanner;
    public class Calculator
    {
       public static void main(String[]args)
      {
       int num1;
      int num2;
      int calc1;
      double calc2;
      Scanner in=new Scanner(System.in);
      System.out.println("First number here");
      num1=in.nextInt();
      System.out.println("What do you want to do? add = 1 subtract = 2 divide = 3 multiply = 4");
      calc1=in.nextInt();
      System.out.println("Second number here");
      num2=in.nextInt();
    calc2=0; 
    
    if (calc1 == 1)
        calc2=(double)num1+num2;
      if (calc1 == 2)
        calc2=(double)num1-num2;
    if (calc1 == 3)
      calc2=(double)num1/num2;
    if (calc1 == 4)
      calc2=(double)num1*num2;
    System.out.println("Your answer is " +calc2);
       }
    }
    
    outcome :
    Code:
    First number here
    1000
    What do you want to do? add = 1 subtract = 2 divide = 3 multiply = 4
    2
    Second number here
    500
    Your answer is 500.0
    
    question:
    the command or however you call it for inputting an int is in.nextInt();
    I've tried a few combinations of in.next[whatever]
    i just want to know how to input char's so i can make my calc improved
     
  3. Unread #2 - Oct 17, 2007 at 1:07 PM
  4. Bori
    Joined:
    Mar 4, 2006
    Posts:
    11
    Referrals:
    0
    Sythe Gold:
    0

    Bori Newcomer

    A lame calc | and a question about char's

  5. Unread #3 - Oct 17, 2007 at 1:59 PM
  6. speljohan
    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0

    speljohan Guru
    Visual Basic Programmers

    A lame calc | and a question about char's

    You could always use a DataInputStream instead. Just do:
    Code:
    		DataInputStream dis = new DataInputStream(System.in);
    		dis.readLine();
    To read the whole line.
     
< Need help on VB | This is not runescape related its for sythe.org >

Users viewing this thread
1 guest


 
 
Adblock breaks this site