java - Modular calculator getting data inside a String array -
i'm stuck on problem codeabbey. don't want answer entire thing.
this meat of question:
input data have:
- initial integer number in first line;
- one or more lines describing operations, in form sign value sign either + or * , value integer;
- last line in same form, sign % instead , number result should divided remainder.
answer should give remainder of result of operations applied sequentially (starting initial number) divided last number.
my problem logic. far realize there operator, space , number. number thought of using
char c = src.charat(2); and operator i'd use same thing. i'd use bunch of if-else statements figure out rest. how do in large scale? how read of numbers in , every 1 of them? nudge on right direction help.
import java.util.scanner; public class challenge14 { static scanner in = new scanner(system.in); public static void main(string[] args) { system.out.println("enter first number: "); int x = in.nextint(); (int = 0; < 7; i++) { string[] s = new string[i]; s = in.nextline(); } } }
one of more helpful classes problem scanner.
the scanner documentation located at: https://docs.oracle.com/javase/7/docs/api/java/util/scanner.html
the scanner can set read string, file, or input stream.
the scanner has several useful methods, including:
- hasnext(), lets know if there other operators or numbers pick up
- next(), read next token string
- nextint(), read next token int
you can use scanner pick first number, use sort of loop perform operations on number until there no more operations perform.
Comments
Post a Comment