java - Code for Simple Arithmetic -


i new programming, first year college of bsit , tasked code simplearithmetic ask name first , after asked enter first , second integer.

after giving asked must show "hello (the name entered)" follows next sum, difference, product , mod of 2 integers , lastly show "thank you!".

i tried lot of codes not run, can me? appreciate because want learn how happen.

this code

public class simplearithmetic{      public static void main(string[] args){      //1: declare name symbol     //2: num 1, num 2, sum, difference, product, mod 0;      system.out.print("enter name: ");     name = in.next();    // <---- here     system.out.printf("\nenter first integer: ");     system.out.printf("\nenter second integer: ");     system.out.printf("\nnum 1 + num 2");     system.out.printf("\nnum 1 - num 2");     system.out.printf("\nnum 1 * num 2");     system.out.printf("\nnum 1 % num 2");     system.out.print("hello \n + name");     system.out.println("num 1" + "+" + "is" + "sum");     system.out.println("num 1" + "-" + "is" + "difference");     system.out.println("num 1" + "*" + "is" + "product");     system.out.println("num 1" + "%" + "is" + "mod");     system.out.print("thank you!");     }  } 

the bold 1 error when tried compile java file

use class scanner below read input:

scanner scanner = new scanner(system.in);  // init scanner string name = scanner.nextline();          // reads full line int = scanner.nextint();                 // reads 1 integer int b = scanner.nextint();                 // reads integer 

check documentation here if know more class scanner.

basically scanner useful class read input stream (system.in) in case. javadoc

a simple text scanner can parse primitive types , strings using regular expressions.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -